2013-02-19 83 views
0

我无法第二次调用.replaceWith覆盖用.replaceWith编写的旧内容。你如何处理如下问题:JavaScript/jQuery链接标记替换调用

if (data==-3){ 
     $('message').replaceWith('ffgd');           
} else if (data==-4){ 
     $('message').replaceWith('dfdsfdsfds'); 

在数据为-3的第一次调用时,我看到ffgd。然后,当发生第二次调用并且data = -4时,我知道else if块由于console.log消息而运行,但它不会覆盖ffgd。

+0

是'message'的元素? – j08691 2013-02-19 03:30:05

+0

它是一个标签 Andy 2013-02-19 03:31:01

回答

1

一旦您使用replaceWith原始元素消失...没有message标记替换第二次。

也许你要替换它的可使用text()html()方法

见API文档来完成的内容:http://api.jquery.com/replaceWith/

+0

好赶上,谢谢:) – Andy 2013-02-19 03:37:27