欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery中removeData()方法用法實(shí)例

 更新時(shí)間:2014年12月27日 15:03:36   投稿:shichen2014  
這篇文章主要介紹了jQuery中removeData()方法用法,實(shí)例形式分析了removeData()方法移除匹配元素指定數(shù)據(jù)的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了jQuery中removeData()方法用法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

此方法可以移除匹配元素上指定的數(shù)據(jù)。
removeData()方法與data()方法的作用相反。

語法結(jié)構(gòu)一:

復(fù)制代碼 代碼如下:
$(selector).removeData(name)

參數(shù)列表:

參數(shù) 描述
name 可選。定義要?jiǎng)h除的數(shù)據(jù)的名稱。
如果沒有定義名稱,該方法將從被選元素中刪除所有已存儲(chǔ)的數(shù)據(jù)。

實(shí)例代碼:

復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.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ù),最后檢測(cè)數(shù)據(jù)是否刪除。

希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論