removeAttr()方法是jQuery中的一个内置方法,用于 从选定元素中删除一个或多个属性。
null
语法:
$(selector).removeAttr(attribute)
参数: 此函数接受单个参数 属性 这是强制性的。它用于指定要删除的一个或多个属性。可以使用空格运算符分隔多个属性。
返回值: 此方法返回具有移除属性的选定元素。
下面的示例演示了jQuery中的removeAttr()方法:
例子:
<!DOCTYPE html> < html > < head > < title >The removeAttr Method</ title > < script src = </ script > <!-- jQuery code to show the working of this method --> < script > $(document).ready(function() { $("button").click(function() { $("p").removeAttr("style"); }); }); </ script > < style > div { width: 300px; min-height: 150px; border: 2px solid green; padding: 20px; text-align:center; } </ style > </ head > < body > < div > <!-- click on the any of the paragraph and see the change --> < p style="font-size:35px;font-weight:bold; color:green;">Welcome to</ p > < p style="font-size:35px;font-weight:bold; color:green;">GeeksforGeeks!.</ p > < button >Click Here!</ button > </ div > </ body > </ html > |
输出:
jQuery是一个开源JavaScript库,可以简化HTML/CSS文档之间的交互,它以其独特的编程理念而广为人知 “少写多做” . 通过以下步骤,您可以从头开始学习jQuery jQuery教程 和 jQuery示例 .
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END