Edit The Code:
See Result »
Try it Yourself - ©
w3big.com
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>本教程(w3big.com)</title> <script src="http://cdn.static.w3big.com/libs/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("#btn1").click(function(){ $("div").data("greeting", "Hello World"); alert("问候: " + $("div").data("greeting")); }); $("#btn2").click(function(){ $("div").removeData("greeting"); alert("问候: " + $("div").data("greeting")); }); }); </script> </head> <body> <button id="btn1">附加数据到div元素</button><br> <button id="btn2">移除附加到div元素的数据</button> <div></div> </body> </html>