jQuery DOM ?? ?? ??? ??? ???
??? ??? ????? ?? jQuery? ?? ??() ? ??([expr])?? ? ?? ???? ?????. ? ? ??? ????? ? ???? ??? ???? ????.
empty ???
empty() ???? ??? ???? ??? ??? ????. ??? ?? ?? ??? ?? ? ????.
? ?? ??? ?? ??? ??? ? ????.
remove ???
? ? ??? ??? ??? ?? ?? ?? ??? ??? ?????
??? ???? ??? ???? ??? ???? ?????
????? ??? ???? ??? ?????
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>remove()與empty()的區(qū)別</title> <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script> <style type="text/css"> #dv1{ width:250px; height:250px; background:red; float:left; } #dv2{ width:250px; height:250px; background:green; float: left; margin-left:5px; margin-right:5px; } </style> </head> <body> <div id="dv1"> <p>元素1</p> <p>元素2</p> </div> <div id="dv2"> <p>元素3</p> <p>元素4</p> </div> <input type="button" value="empty" id="but1"> <input type="button" value="remove" id="but2"> <script> $("#but1").click(function(){ $("#dv1").empty(); }) $("#but2").click(function(){ $("#dv2").remove(); }) </script> </body> </html>
? ??? ???? ??? ? ? ????. ???? ???? Element 1? Element 2? ????? div? ??? ?????
??? ???? ?? ?? ???? ??? div ??? ?????