Chr*_*Ian 3 html javascript jquery x-editable
在x-editable库中.如何输入数字?这不允许输入框中的任何字母.
我试过这段代码
<a class="items" data-name="itemqty" data-title="Enter Item Quantity" data-type="text" href="#" id="itemqty" onkeypress="return isNumberKey(event)"></a>
<script>
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
} else {
return true;
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
但它不起作用.如果我使用普通输入文本它可以工作,但在x-editable中它不起作用.有任何想法吗?
以下解决方案适合我:
$('.editable').editable({
type: 'text',
validate: function(value) {
if ($.isNumeric(value) == '') {
return 'Only numbers are allowed';
}
}
});
Run Code Online (Sandbox Code Playgroud)
返回错误字符串很重要(例如'只允许数字'),否则x-editable不会识别验证失败.
| 归档时间: |
|
| 查看次数: |
7076 次 |
| 最近记录: |