Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在javascript或jquery中无模式地在文本输入字段中输入数字_Javascript_Jquery - Fatal编程技术网

如何在javascript或jquery中无模式地在文本输入字段中输入数字

如何在javascript或jquery中无模式地在文本输入字段中输入数字,javascript,jquery,Javascript,Jquery,我正在尝试模式,但它对我的主题不起作用。现在我认为使用javascript或jquery很好 <input name="abc" id="abc" type="text" required="required" tabindex="1"/> 数值的javascript或jquery代码是什么(不是负数)这是使用javascript所能做的一切 var val=document.getElementById('abc').value; if(isNaN(val)

我正在尝试模式,但它对我的主题不起作用。现在我认为使用javascript或jquery很好

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


数值的javascript或jquery代码是什么(不是负数)

这是使用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');
    }
var val=document.getElementById('abc').value;
if(伊斯南(瓦尔)){
警报(“这不是一个数字”);
}else if(val<0){
警报(“这是一个负数”);
}否则{
警报(“这是一个数字”);
}
您也可以像使用HTML5 dom一样使用它

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

试试HTML5控件。你会得到所有这些

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


我问js和jquery你到底想做什么?就像@user1671639一样,我也没有回答你的问题。
document.getElementById('abc')。value=10
$('abc')。val('10')
继续使用相同的问题来获得你需要的结果。你不必每次都创建一个新的。