0
我想要做的操作來刪除最接近的表,當某些措辭存在於html。jquery刪除最接近tr失敗
我不能假定span類將存在那裏,因爲html是從另一端檢索的,他們可以通過添加,隨時刪除任何類來更改它。
它需要在頁面加載時完成,而不是點擊裏面的class/id事件。
有點具有挑戰性。任何想法如何實現這一目標?
在頁面加載,
jQuery來檢測是否「你好你怎麼樣」的頁面存在。如下
If exist
remove the whole td or tr or table for this particular.
else
do nothing.
end
代碼:
function replaceText()
{
var debug;
debug= "";
$("*").each(function() {
if($(this).children().length==0)
{
// $(this).text($(this).text().replace('Hello how are you', 'yohoo'));
debug= debug + $(this).val() + "<br>";
if($(this).val()=="Hello how are you")
{
$(this).closest('table').remove();
}
}
});
//alert(debug);
}
<div>
<table>
<tr>
<td colspan="2">
<div>
<table>
<tr>
<td ><span class="myclass">Hello how are you</span></td>
<td><a href="testing.php"></a></td>
</tr>
</table>
</div>
</td>
</tr>
<tr colspan="2">
<table>
<tr>
<td><b>want to remove this</b></td>
</tr>
</table>
</tr>
<tr>
<td>other content 1</td>
<td>other content 2</td>
</tr>
</table>
</div>
我想你想`的.text()``不.VAL()`。 val是用於輸入,選擇,textareas ... – 2011-02-04 05:58:25