在Enter上添加br标签

时间:2015-05-21 05:55:33

标签: javascript jquery

每次在<br />函数中按下输入时,如何添加keyup标记?我不知道应该怎么做。

.on("keyup", ".club", function() {
     //detect enter key to add br tags
});

1 个答案:

答案 0 :(得分:2)

试试这个:

.on("keyup", ".club", function(e) {
    if (e.keyCode === 13) {
        var $this = $(this); // Caching
        $this.val($this.val() + '<br />');

        // OR

        $this.val($this.val() + '\n\r');
    }
});
相关问题