2010-07-07 74 views

回答

5

你可以尝试这样的事:

http://jsfiddle.net/5sYFT/1/

var text = $('textarea').val(); 

text = text.replace(/\[quote="comment-(\d+)"\]/g, function(str,p1) { return $('#comment-' + p1).text(); }); 

$('textarea').val(text); 

应该匹配agains在你给的格式的任何编号报价。

+0

作品,谢谢:P – Alex 2010-07-07 00:22:48

0

您可以使用正则表达式:

text = text.replace(/\[quote="([a-z0-9-]+)"]/gi, 
    function(s, id) { return $('#' + id).text(); } 
); 
0

如果我理解正确的话,你要替换类似“[报价=‘评论-1’]”与“”。

在JavaScript:

// Where textarea is the reference to the textarea, as returned by document.getElementById 
var text = textarea.value; 
text = text.replace(/\[quote\="(comment\-1)"\]/g, '<div id="$1">'); 

在jQuery中:

// Where textarea is the reference to the textarea, as returned by $() 
var text = textarea.val(); 
text = text.replace(/\[quote\="(comment\-1)"\]/, '<div id="$1">'); 

希望这有助于!