Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jquery/javascript中中断用户输入_Javascript_Jquery_Keypress_Keyup - Fatal编程技术网

在jquery/javascript中中断用户输入

在jquery/javascript中中断用户输入,javascript,jquery,keypress,keyup,Javascript,Jquery,Keypress,Keyup,有没有办法中断用户输入? 例如,用户将在文本框中键入其物理地址, 当他输入他的值时,我想插入“-”字符 以便用户何时键入“002255667788” 我可以自动将其格式化为“00-22-55-66-77-88” 我可以用键盘按吗?谢谢。您可以使用 使用起来非常简单,只需添加您想要设置号码格式的方法: $(document).ready(function(){ $('#your_id').mask('11-11-11-11-11'); }); 举个例子。如果使用jQuery,您可以收听模糊事

有没有办法中断用户输入? 例如,用户将在文本框中键入其物理地址, 当他输入他的值时,我想插入“-”字符 以便用户何时键入“002255667788” 我可以自动将其格式化为“00-22-55-66-77-88”

我可以用键盘按吗?谢谢。

您可以使用

使用起来非常简单,只需添加您想要设置号码格式的方法:

$(document).ready(function(){
  $('#your_id').mask('11-11-11-11-11');
});

举个例子。

如果使用jQuery,您可以收听模糊事件并格式化输入值:

$('#your_input').on('blur', function(){
    //clean the non numeric values
    this.value = this.value.replace(/[^\d]/g,'')
    //place the dashes
    .replace(/(\d{2})/g,'$1-')
})

您也可以更改关键事件的值,但要小心检测它何时为
delete
enter
,等等。

是否总是每2个字符一次?是的。它是一个计算机系统的物理地址。是的,您可以在keyup、keydown或keypress上执行。typeerror:$(…)。掩码不是一个函数。是的,当然,您需要下载jQuery插件