Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript或jquery替换标记中的文本_Javascript_Jquery_Replace - Fatal编程技术网

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");