我想在文本中查找並替換@jo
for @josh
。在jquery中更改單詞一次
我的問題是,如果我繼續單擊跨度輸出成爲這樣的事情:
@joshshsh
JS
$(document).on("click", ".cclass", function() {
var p = '@jo';
var username = '@josh';
$("#comment").val($("#comment").val().replace(p, username)); //want to replace @jo to @josh just once
});
什麼想法?
https://jsfiddle.net/pL6ut0ac/
當您完成更換時刪除點擊事件? – Mistergreen