开发者

Restrict carriage return on writable div

I have made a div writable by adding contentEditabl开发者_JS百科e="true". I want to restrict the text to one line and restrict users to enter multiple lines. How can i do that?


Bind a function to the keypress event on the div and disallow the enter button

$("div").keypress(function(event){
  if ( event.which == 13 ) {
     event.preventDefault();
   }
});

http://jsfiddle.net/pyeyY/


Here you go:

div.onkeydown = function (e) {
    if ( e.keyCode === 13 ) { e.preventDefault(); }
};

Live demo: http://jsfiddle.net/3QbCk/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜