你好朋友:)jquery替换元素中的多个字符串,而不是替换元素
我有一个关于jquery的问题。在jQuery中有一个函数来替换已经映射到对象或数组中的许多单词。
例在PHP中:
<?php
$textBefore = "PHP is amazing open source programmer language,
there many webs around the world that are built using php";
$forReplace = array("amazing","programmer","webs");
$replacement = array("powerfull","programming","websites");
$textAfter = str_replace($forReplace , $replacement , $textBefore);
echo $textAfter;
?>
将产生
PHP is powerfull open source programming language,
there many websites around the world that are built using php
如何在jQuery中做类似的事情? 我这样做是为了降低服务器的性能,所以我想通过浏览器来完成这项工作。因为在一个演出页面中替换的内容太多了。
在此先感谢。
我已经知道,但我需要的是一个功能,同时运行所有的转。这是否意味着我必须一遍又一遍地做,而不映射对象?这是最后一个? – kefy 2014-09-03 08:10:57
因为它也是工作,所以我会将您的答案投票。 :) – kefy 2014-09-03 08:16:30
我添加了代码,向您展示如何复制PHP的str_replace方法。 – 2014-09-03 08:19:42