Javascript或jquery替换标记中的文本
例如:Javascript或jquery替换标记中的文本,javascript,jquery,replace,Javascript,Jquery,Replace,例如: <a href=''>Hello</a> 我想使用jquery或Javascript将所有A标记中的字符串“Hello”替换为“notgood” 结果如下: <a href=''>Not Good</a> 我该怎么做呢?请尝试一下 $('a').text('Not Good'); 尝试使用此功能。您只需执行以下操作: $("a").html("Not Good"); //or $("a").text("Not
<a href=''>Hello</a>
我想使用jquery或Javascript将所有A标记中的字符串“Hello”替换为“notgood”
结果如下:
<a href=''>Not Good</a>
我该怎么做呢?请尝试一下
$('a').text('Not Good');
尝试使用此功能。您只需执行以下操作:
$("a").html("Not Good");
//or
$("a").text("Not Good");
试试这个
$("a").text("Not Good");
尝试:
我想将所有A标记中的字符串“Hello”替换为“notgood”
假设“Hello”不是a
元素的唯一内容,而是只包含文本:
$("a").text(function(_, text) {
return text.replace('Hello', 'Not Good');
});
如果在同一a
元素中多次出现“Hello”,请使用正则表达式(/Hello/g
)而不是简单的字符串
参考:,。您可以为该链接指定一个id,然后更改其文本。它将避免替换其他超链接的文本
<a id="hello" href=''>Hello</a>
$("#hello").html("Not Good");
or
$("#hello").text("Not Good");
$(“#你好”).html(“不好”);
或
$(“你好”).text(“不好”);
$('a')。文本('notgood');很好去
<a id="hello" href=''>Hello</a>
$("#hello").html("Not Good");
or
$("#hello").text("Not Good");