如何在所有<span>标记中搜索字符串,然后将该字符串替换为另一个字符串</span>

时间:2011-07-24 13:34:37

标签: jquery html

我实际上正在为我的网站制作一个不同的按钮。 我到目前为止使用的代码 -

$(".unlike").click(function(){
  var pid = $(this).attr("id");
  var email = $("#hidden").val();
  var data = "pid="+pid+"&email="+email;
  $("#flash").show();
  $("#flash").fadeIn(500).html('<img src="wamp.gif" /> Loading...');
  $.ajax({
    type: "POST",
    url: "unlike.php",
    data: data,
    cache: false,
    success: function(html) {
        $("#flash").fadeOut(100);
        $("#likes"+id).text(html).replaceWith('');
    }
});

});

此代码是点击不同按钮时发生的情况。 它将数据发送到different.php文件,在那里它从likes表中删除了人的名字,我想要的是它还应该从标签中删除名称

2 个答案:

答案 0 :(得分:1)

试试这个。

$("span:contains('{enter your search string here}')").each(function(){
     $(this).html($(this).text().replace( /{enter your search string here}/g, "{enter your new string here}" );
});

答案 1 :(得分:0)

$('span').each(function(){
      $(this).text().replace(/find/g,”replace”)
})
相关问题