2

我尝试通过使用contenteditable提交一些标题来制作一个元素,这样我希望用户只输入/粘贴标题一行

$('.title').on('keypress',function(e) {
   var code = e.keyCode || e.which;
   if(code == 13) {
      e.preventDefault();
   }
}).on('paste',function(){
   var text = $(this).text();
   $(this).html(text).focus();
});

问题是paste事件,当我粘贴一些文本时,我不能.focus()用来选择/指向最后一个字符的文本。

我做错了什么?

4

1 回答 1

4

我现在有想法了...

jQuery :

$('.title').on('keypress',function(e) {
   var code = e.keyCode || e.which;
   if(code == 13) {
      e.preventDefault();
   }
}).on('paste',function(){
   $('br,p',this).replaceWith(' ');
});

CSS : (不是请求)

.title br {display:none;}
于 2013-10-09T10:54:38.120 回答