Home > Web Front-end > JS Tutorial > Example of usage of removeData() method in jQuery

Example of usage of removeData() method in jQuery

PHPz
Release: 2018-09-30 09:17:27
Original
1704 people have browsed it

This article mainly introduces the usage of the removeData() method in jQuery. It analyzes the technique of removeData() method to remove the specified data of matching elements in the form of examples. It has certain reference value. Friends who need it can refer to it

The example in this article describes the usage of the removeData() method in jQuery. Share it with everyone for your reference. The specific implementation method is as follows:

This method can remove the specified data on the matching element.
The removeData() method has the opposite effect to the data() method.

Grammar structure one:

$(selector).removeData(name)
Copy after login

Parameter list:

< td style="border-bottom: rgb(227,237,245) 1px solid; border-left: rgb(227,237,245) 1px solid; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; word-wrap: break- word; font-size: 14px; overflow: hidden; border-top: rgb(227,237,245) 1px solid; border-right: rgb(227,237,245) 1px solid; padding-top: 4px">Parameters
参数描述
name可选。定义要删除的数据的名称。
如果没有定义名称,该方法将从被选元素中删除所有已存储的数据。
Description

nameOptional. Defines the name of the data to be deleted. If no name is defined, this method will delete all stored data from the selected elements.

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="//www.jb51.net/" />
<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(){ 
    $("p").data("mydata","脚本之家欢迎您"); 
  }); 
  $("#show").click(function(){ 
    $("p").text($("p").data("mydata")); 
  }); 
  $("#delete").click(function(){ 
    $("p").removeData("mydata"); 
    alert($("p").data("mydata")); 
  }) 
}); 
</script> 
</head> 
<body> 
  <p></p> 
  <button id="add">向元素添加数据</button> 
  <button id="show">显示添加的数据</button> 
  <button id="delete">删除元素中的数据</button> 
</body> 
</html>
Copy after login

Example code:

The above code can be specified through the data() method The element appends data, then uses the removeData() method to delete the data, and finally detects whether the data has been deleted.

The above is the entire content of this chapter. I hope it will be helpful to everyone’s jQuery programming. For more related tutorials, please visit jQuery Video Tutorial!
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template