允许“Enter”键工作,但不中断给定的行

Allow "Enter" key working but not breaking line given

本文关键字:中断 Enter 工作 允许      更新时间:2023-09-26

嗨,我需要在这里实现隔断线,因为您可以键入 enter,但再次键入后没有给出断行。

我把这个小提琴 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)
});

js 中添加此代码

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

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