我呼吁keypress
功能,其中不允许字母值,但允许有进,退格数字字符,删除,箭头等不允许字母值,但允许进入,退格键,删除,箭头等
function checkIt(s) {
if (s.match('/[^a-zA-Z0-9 ]/g')) {
s = s.replace('/[^a-zA-Z0-9 ]/g', '');
}
}
HTML
<input type="text" onkeyup="return checkIt(this.value)" maxlength="4" class="input-layout" value="10" name="test[]">
<input type="text" onkeyup="return checkIt(this.value)" maxlength="4" class="input-layout" value="10" name="test[]">
<input type="text" onkeyup="return checkIt(this.value)" maxlength="4" class="input-layout" value="10" name="test[]">
<input type="text" onkeyup="return checkIt(this.value)" maxlength="4" class="input-layout" value="10" name="test[]">
此代码无法使用。
这是应该做的。该函数实际上不会返回值或更改任何内容,因为它正在影响局部变量。 – DGS