当我在文本框中插入一个值时,我得到一个 <br />
当我按 Enter 插入换行符时标记。我应该如何删除 <br />
标记并使用 jQuery 替换为换行符。
$('#dbDocumentFooter').keyup(function(e){
var TextToBeDisplayed = $(this).val();
if(e.keyCode == 13 && !e.shiftKey) {
TextToBeDisplayed = $('#dbDocumentFooter').val().replace("\n", "<br />", "g")
$('#dbDocumentFooter').val(TextToBeDisplayed);
}
});
最佳答案
试试这个 https://jsfiddle.net/qa3q9w3r/
$('#dbDocumentFooter').keydown(function(e){
if(e.keyCode == 13 && !e.shiftKey) {
e.target.value+="\n";
e.preventDefault();
}
});
关于javascript - 如何替换 TextBox 中的 <br/>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37351516/