jQuery中removeProp()方法用法实例
本文实例讲述了jQuery中removeProp()方法用法。分享给大家供大家参考。具体分析如下:
此方法可以删除由prop()方法设置的属性。
语法:
$("selector").removeProp(name)
参数列表:
实例:
实例一:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<metaname="author"content="https://www.nhooo.com/"/>
<head>
<title>毛票票</title>
<scripttype="text/javascript"src="mytest/jQuery/jquery-1.8.3.js"></script>
<scripttype="text/javascript">
$(document).ready(function(){
$("td").prop({width:"200",height:"300"});
$("button").click(function(){
$("td").removeProp("width");
})
})
</script>
</head>
<body>
<tableborder="1">
<tr>
<td>欢迎来到毛票票</td>
</tr>
</table>
<button>删除属性</button>
</body>
</html>
以上代码可以删除td的width属性。
实例二:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<metaname="author"content="https://www.nhooo.com/"/>
<head>
<title>毛票票</title>
<styletype="text/css">
td
{
width:200px;
}
</style>
<scripttype="text/javascript"src="mytest/jQuery/jquery-1.8.3.js"></script>
<scripttype="text/javascript">
$(document).ready(function(){
$("td").prop({height:"300"});
$("button").click(function(){
$("td").removeProp("width");
})
})
</script>
</head>
<body>
<tableborder="1">
<tr>
<td>欢迎来到毛票票</td>
</tr>
</table>
<button>删除属性</button>
</body>
</html>
以上代码并没有删除td的width属性,这是因为removeProp()只能删除由prop()方法设置的属性。
希望本文所述对大家的jQuery程序设计有所帮助。