jQuery - ?? ??
??/??? ??
??? ???? ???? ?? ?? ????? ?? ? ?? jQuery ???? ??? ? ????.
remove() - ??? ??(? ?? ?? ??) ??
empty() - ?? ??? ???? ?? ?? ??
remove() ???
jQuery Remove() ???? ??? ??? ?? ?? ??? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").remove(); }); }); </script> </head> <body> <div id="div1" style="height:100px;width:200px;border:1px solid black;background-color:pink;"> 你好 <p>你很好</p> <p>你太好了</p> </div> <br> <button>移除</button> </body> </html>
empty() ???
jQueryempty() ???? ??? ??? ?? ??? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").empty(); }); }); </script> </head> <body> <div id="div1" style="height:100px;width:200px;border:1px solid black;background-color:yellow;"> 你好 <p>你很好</p> <p>你太好了</p> </div> <br> <button>清空</button> </body> </html>
??? ?? ???
jQuery Remove() ???? ????? ????? ??? ??? ???? ? ????.
? ????? jQuery ??? ??? ? ????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").remove(".italic"); }); }); </script> </head> <body> <p>這是一個(gè)段落。</p> <p class="italic"><i>這是另外一個(gè)段落。</i></p> <p class="italic"><i>這是另外一個(gè)段落。</i></p> <button>移除所有 class="italic" 的 p 元素。</button> </body> </html>