WWW.lllT.neT
方式:1、运用children()和remove()方式删掉特定原素的具体内容,英语的语法为“$(原素).children().remove();”;2、运用empty()方式删掉特定原素的具体内容,英语的语法为“$(原素).empty();”。
本实例教程实际操作自然环境:windows7系统软件、jquery1.10.0版本号、Dell G3电脑上。
jquery怎样去除原素具体内容
在jquery中,可以给标识内的部份具体内容标识设定id特性,根据该id得到一部分具体内容目标。
如需删掉原素和具体内容,一般可应用下列2个 jQuery 方式:
remove() - 删掉被选原素(以及子原素)
empty() - 从被选原素中删掉子原素
下边大家根据实例看来一下这2种方式 的应用,实例如下所示:
1、运用children() 方式返回返回被选原素的全部立即子原素,再根据jQuery remove() 方式删掉被选原素以及子原素。
<!DOCTYPE html> <html> <head> <script src="/jquery/jquery-1.11.1.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").children().remove(); }); }); </script> </head> <body> <div id="div1" style="height:120px;width:300px;border:1px solid black;background-color:yellow;"> <p>This is some text in the div.</p> <p>This is a paragraph in the div.</p> <p>This is another paragraph in the div.</p> </div> <br> <button>删掉 div 原素</button> </body> </html>
导出結果:
2、jQuery empty() 方式删掉被选原素的子原素。
<!DOCTYPE html> <html> <head> <script src="/jquery/jquery-1.11.1.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").empty(); }); }); </script> </head> <body> <div id="div1" style="height:100px;width:300px;border:1px solid black;background-color:yellow;"> This is some text in the div. <p>This is a paragraph in the div.</p> <p>This is another paragraph in the div.</p> </div> <br> <button>清除 div 原素</button> </body> </html>
导出結果:
有关教程视频建议:jQuery教程视频
以上便是jquery怎样去除原素具体内容的详尽具体内容,大量请关心自学java网其他相关文章!
WWW.lllT.neT声明:有的资源来自网络转载,版权归原作者所有,如有侵犯到您的权益请联系邮箱:our333@126.com我们将配合处理!
原文地址:jquery怎样去除原素具体内容发布于2021-12-09 14:00:02