.removeData()
.removeData( [ name ] ) 返回: jQuery
描述: 在元素上移除绑定的数据
-
version added: 1.2.3.removeData( [ name ] )
name要移除的存储数据名.
.removeData()
方法允许我们移除用.data()
绑定的值。当带name参数调用的时候,.removeData()
将删除那个特有的值,当不带任何参数的时候,所有的值将被移除。
例子:
Set a data store for 2 names then remove one of them.
<!DOCTYPE html>
<html>
<head>
<style>
div { margin:2px; color:blue; }
span { color:red; }
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<div>value1 before creation: <span></span></div>
<div>value1 after creation: <span></span></div>
<div>value1 after removal: <span></span></div>
<div>value2 after removal: <span></span></div>
<script>
$("span:eq(0)").text("" + $("div").data("test1"));
$("div").data("test1", "VALUE-1");
$("div").data("test2", "VALUE-2");
$("span:eq(1)").text("" + $("div").data("test1"));
$("div").removeData("test1");
$("span:eq(2)").text("" + $("div").data("test1"));
$("span:eq(3)").text("" + $("div").data("test2"));
</script>
</body>
</html>