不能在输入中使用箭头

时间:2014-01-31 21:43:56

标签: javascript jquery

嗨我没有制作这个剧本,但它是一个张贴形式,简单只是html,

这是输入中的html

<input class="text_box" type="text" name="title" id="title" size="19" value="Title"  onkeydown="SpecialReplace(this)" onkeyup="SpecialReplace(this)" onblur="SpecialReplace(this)" onclick="SpecialReplace(this)"/>

这是SpecialReplace()函数

function SpecialReplace(o)
{
      o.value=o.value.replace(/[^a-zA-Z0-9 áéíóúÁÉÍÓÚÜüñѨ´,.¿?%&$!¡ªº#"()-_\/]/g,'');
}

我尝试使用箭头,去特定字母“编辑”但我不能使用输入中的箭头,为什么??

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

为什么所有这些内联处理程序如果你使用jQuery?

无论如何,这是你如何做到的:

HTML

<input class="text_box" type="text" name="title" id="title" size="19" value="Title">

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)

});