jQuery中removeData()方法用法實例
本文實例講述了jQuery中removeData()方法用法。分享給大家供大家參考。具體實現(xiàn)方法如下:
此方法可以移除匹配元素上指定的數(shù)據(jù)。
removeData()方法與data()方法的作用相反。
語法結(jié)構(gòu)一:
參數(shù)列表:
實例代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://chabaoo.cn/" />
<title>腳本之家</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#add").click(function(){
$("div").data("mydata","腳本之家歡迎您");
});
$("#show").click(function(){
$("div").text($("div").data("mydata"));
});
$("#delete").click(function(){
$("div").removeData("mydata");
alert($("div").data("mydata"));
})
});
</script>
</head>
<body>
<div></div>
<button id="add">向元素添加數(shù)據(jù)</button>
<button id="show">顯示添加的數(shù)據(jù)</button>
<button id="delete">刪除元素中的數(shù)據(jù)</button>
</body>
</html>
以上代碼能夠通過data()方法向指定元素附加數(shù)據(jù),然后使用removeData()方法刪除數(shù)據(jù),最后檢測數(shù)據(jù)是否刪除。
希望本文所述對大家的jQuery程序設(shè)計有所幫助。
相關(guān)文章
jQuery實現(xiàn)提交表單時不提交隱藏div中input的方法
這篇文章主要介紹了jQuery實現(xiàn)提交表單時不提交隱藏div中input的方法,結(jié)合實例形式分析了通過設(shè)置input的disabled屬性實現(xiàn)隱藏input提交的操作技巧,需要的朋友可以參考下2019-10-10easyui datebox 時間限制,datebox開始時間限制結(jié)束時間,datebox截止日期比起始日期大的實現(xiàn)代碼
這篇文章主要介紹了easyui datebox 時間限制,datebox開始時間限制結(jié)束時間,datebox截止日期比起始日期大的實現(xiàn)代碼,需要的朋友參考下吧2017-01-01