這篇文章主要介紹了jQuery中removeProp()方法用法,實例分析了removeProp()方法的功能、定義及刪除由prop()方法設置的屬性時的使用技巧,需要的朋友可以參考下
本文實例講述了jQuery中removeProp()方法用法。分享給大家供大家參考。具體分析如下:
此方法可以刪除由prop()方法設置的屬性。
語法:
復制代碼代碼如下:
$("selector").removeProp(name)
參數列表:
實例:
實例一:
復制代碼代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http://www.49028c.com/" />
<head>
<title>武林網</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("td").prop({width:"200",height:"300"});
$("button").click(function(){
$("td").removeProp("width");
})
})
</script>
</head>
<body>
<table border="1">
<tr>
<td>歡迎來到武林網</td>
</tr>
</table>
<button>刪除屬性</button>
</body>
</html>
以上代碼可以刪除td的width屬性。
實例二:
復制代碼代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http://www.49028c.com/" />
<head>
<title>武林網</title>
<style type="text/css">
td
{
width:200px;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("td").prop({height:"300"});
$("button").click(function(){
$("td").removeProp("width");
})
})
</script>
</head>
<body>
<table border="1">
<tr>
<td>歡迎來到武林網</td>
</tr>
</table>
<button>刪除屬性</button>
</body>
</html>
以上代碼并沒有刪除td的width屬性,這是因為removeProp()只能刪除由prop()方法設置的屬性。
希望本文所述對大家的jQuery程序設計有所幫助。