empty()方法是jQuery中的一个内置方法,用于删除选定元素的所有子节点及其内容。
null
语法:
$(selector).empty()
参数: 此方法不接受任何参数。
返回值: 此方法返回所选元素,其中包含empty()方法所做的指定更改。
下面的示例演示了jQuery中的empty()方法:
例子:
<!DOCTYPE html> < html > < head > < title >The empty Method</ title > < script src = </ script > <!-- jQuery code to show the working of this method --> < script > $(document).ready(function() { $("button").click(function() { $("body").empty(); }); }); </ script > < style > div { width: 200px; height: 100px; margin: 10px; padding: 20px; background-color: lightgreen; font-weight: bold; font-size: 20px; } button { margin: 10px; } </ style > </ head > < body > < div > Hello ! < p >Welcome to < span >GeeksforGeeks</ span >.</ p > </ div > <!-- click on this button to see the change --> < button >Click here..!</ button > </ body > </ html > |
输出: 单击按钮之前: 单击按钮后,将不会显示任何内容:
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END