Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是我得到的-:
<div contenteditable="true">Hey man @tt</div>
现在我想在输入<a></a>时环绕@。
<a></a>
@
例如,当@被按下时,html 将是
<div contenteditable="true">Hey man <a>@</a>tt</div>
使用replace().
replace()
尝试这个
var output= $('div').html().replace('@','<a>@</a>'); $('div').html(output);
在这里摆弄
$('input').keypress(function(e){ if ((e.shiftKey == true) && (e.charCode == 64)) { $(this).html().replace('@','<a>@</a>'); } });