日期:2014-05-16 浏览次数:20410 次
$.get( url, function(data){ if(data == "abc"){ $("#Result") .each(function(i){ // 服務器返回了“abc”,意味著我要刪掉下面 html 裏 // “<div class="Item"><span class="ItemValue">abc</span></div>” // 這行。 // 請問這個代碼這裡該怎麽寫?謝謝 } }); } } );
<div id="Result"> <div class="Item"><span class="ItemValue">123</span></div> <div class="Item"><span class="ItemValue">abc</span></div> <div class="Item"><span class="ItemValue">xyz</span></div> </div>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script> </head> <body> <div id="Result"> <div class="Item"><span class="ItemValue">123</span></div> <div class="Item"><span class="ItemValue">abc</span></div> <div class="Item"><span class="ItemValue">xyz</span></div> </div> <script type="text/javascript"> var data = 'abc'; if (data == 'abc') { $("#Result .ItemValue").each( function() { if ($(this).text() == 'abc') $(this).parent().remove(); }); } </script> </body> </html>