您的位置:首页 > Web前端 > JavaScript

input的onchange事件 及只能输入数字实现

2017-09-06 00:00 513 查看
摘要: input内容发生变化时 需要出发一些动作

<input type="text" class="currentPage">
<script>
// method1
$(".currentPage").on('input',function(e){
alert("TextChanged!") ;
});
//method2
$(".currentPage").bind("propertychange input",function(){
alert("TextChanged!") ;
})
</script>

input输入框只能输入数字:

<input id="xxx" type="number" onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"/>

输入整数或者小数:

<input id="xxx" type="number" onKeypress="return (/[\d+([.]\d)]/.test(String.fromCharCode(event.keyCode)))"/>

控制输入金额:

$("#withdrawAmount").change(function(){
if (utils.isEmpty(this.value)){
this.value = 0;
} else if (this.value > can_out_amount){
var s_amount = can_out_amount.toString();
this.value = s_amount;
if (s_amount.indexOf('.') > 0) {
this.value = s_amount.substring(0, s_amount.indexOf('.'));
}
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  JavaScript Options