1、input type为number时,如何隐藏向上向下的箭头
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
}
input[type="number"]{
-moz-appearance: textfield;
}
2、input框设置为number,禁止输入字符e,
<input id="xxx" type="number" onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))" style="width:475px;ime-mode:Disabled" ></span>
ime-mode的语法解释如下:
ime-mode : auto | active | inactive | disabled
取值:
auto : 默认值。不影响IME的状态。与不指定 ime-mode 属性时相同
active : 指定所有使用IME输入的字符。即激活本地语言输入法。用户仍可以撤销激活IME
inactive : 指定所有不使用IME输入的字符。即激活非本地语言。用户仍可以撤销激活IME
disabled : 完全禁用IME。对于有焦点的控件(如输入框),用户不可以激活IME
第二种就是type为text类型
<input type="text" onkeyup="this.value=this.value.replace(/[^\d]/g,'') " onafterpaste="this.value=this.value.replace(/[^\d]/g,'')"
name="f_order" value="1"/>
其中,onafterpaste防止用户从其它地方copy内容粘贴到输入框
3、检测string中是否有某一个字符的方法有三种
indexOf() !== -1,为true则表示包含
search() !== -1, 为true则表示包含
match():
var reg = RegExp(/3/);
if(str.match(reg)){
// 包含
}
网友评论