我如何在文本输入字段中输入数字,而无需在 JavaScript 或 jQuery 中输入模式

how i can enter digit in text input field without pattern in javascript or jquery

本文关键字:输入 JavaScript 输入模式 jQuery 数字 文本 字段      更新时间:2023-09-26

>我正在尝试使用模式,但它不适用于我的主题。现在我认为在javascript或jquery中工作是件好事。

 <input name="abc" id="abc" type="text" required="required" tabindex="1"/>

什么是 JavaScript 或 jQuery 数值代码(不是负数)

尝试 HTML 5 控件。你会得到这一切。

<input type="number" name="quantity" min="1" max="5" pattern=/[0-9]/>

这就是你可以用javascript做的所有事情。

   var val=document.getElementById('abc').value;
    if(isNaN(val)){
       alert('This is not a Number');
    }else if(val< 0){
        alert('This is a negative Number');
    }else{
       alert('This is a Number');
    }

你也可以像 HTML5 dom 一样使用 HTML5 dom

<input type="number" min="0" />