允许"输入"关键工作,但没有打破线

时间:2014-04-07 07:14:29

标签: javascript jquery

嗨我需要在这里实现断裂线,因为你可以输入回车,但是再次输入后,没有给出断线。

我制作这个小提琴http://jsfiddle.net/FPN9w/

这是JS代码。

$(function () {
    //you have to escaped the - character in a character class
    var cleanRx = /[^a-zA-Z0-9 áéíóúÁÉÍÓÚÜüñѨ´,.¿?%&$!¡ªº#"()\-_\/]/g;

    $('#title').keyup(function (e) {
        var which = e.which;

        //avoid useless replacements when <- and -> keys are pressed
        if (which === 39 || which === 37) return;

        this.value = this.value.replace(cleanRx, '');

    }).trigger('keyup'); //perform replacement on initial content (remove if uneeded)

    $('#description1').keyup(function (e) {
        var which = e.which;

        //avoid useless replacements when <- and -> keys are pressed
        if (which === 39 || which === 37 || which === 13) return;

        this.value = this.value.replace(cleanRx, '');

    }).trigger('keyup'); //perform replacement on initial content (remove if uneeded)

});

1 个答案:

答案 0 :(得分:1)

在js中添加此代码

$('#description1').keydown(function(event){
    if(event.keyCode == 13) {
        event.preventDefault();
       return false;
    }
});

这是您更新的JsFiddle http://jsfiddle.net/pratbhoir/FPN9w/3/