if (document.getElementById("td1").innerHTML == "word"){
$("td:first").html("another word");
}
我只是想检查这是否有这个文本。使用jQuery从元素获取文本
if (document.getElementById("td1").innerHTML == "word"){
$("td:first").html("another word");
}
我只是想检查这是否有这个文本。使用jQuery从元素获取文本
你的意思是
if($('#td1').text() === "word"){
$("td:first").html("another word");
}
此匹配<div id=td1>word</div>
$("#td1:contains('word')").html("another word");
一行代码,我喜欢那个。 – 2012-03-29 10:40:12
@ M.z是的,但如果文本是“密码”或包含“word”的任何其他文本, – 2012-03-29 10:44:14
更妙的是:'$( “TD:第一”)文本( “一个字”);'。举个例子,我不认为OP想插入标记。 – 2012-03-29 10:30:03
@ÁlvaroG.VicarioOP包含问题中的代码 - 这个答案根本没有改变那个代码! – ManseUK 2012-03-29 10:30:51