如何删除使用prop()方法添加的属性
分类:实例代码
大家知道使用prop()方法可以为指定的元素添加属性。那么如何删除使用prop()方法添加的属性呢,下面就通过代码实例做一下介绍。代码实例如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.pipipi.net/" /> <title>前端教程网</title> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.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>
使用removeProp()方法即可实现我们的要求。
具体可以参阅jQuery removeProp()一章节。
一线大厂高级前端编写,前端初中阶面试题,帮助初学者应聘,需要联系微信:javadudu