如何检查文本框是否非空且其值大于0而不是文本?
我想通过 Javascript 使用 IF OR 函数检查文本框值是否为空,以及文本框是否大于 0。
我的代码如下:
if(qty != "" && qty <> "0"){
//
}
其中 qty 是 HTML 输入字段的名称和 id
这是完整更新代码的部分内容。
if(qty != "")
{
if(/^\d+$/.test(qty.value)){
var value = parseint(qty.value, 10);
sizeID = document.getElementById("size" + colID + prodID).value;window.location = "/_nCartAddToBasket.asp?ProductID=" + prodID + "&ProductColourID=" + colID + "&ProductSizeID=" + sizeID + "&Qty=" + qty + "&fgID=" + fgID;
}else{
alert("You must enter a numeric value in the quantity field.");}
}else{
alert("You must enter a quantity before adding to your basket.");}
}
I want to check if a textbox value is empty and also if the textbox is greater than 0 with IF OR function via Javascript.
My code is below:
if(qty != "" && qty <> "0"){
//
}
Where qty is the name and id of the HTML input field
THIS IS THE SOME PORTION FROM THE FULL UPDATED CODE.
if(qty != "")
{
if(/^\d+$/.test(qty.value)){
var value = parseint(qty.value, 10);
sizeID = document.getElementById("size" + colID + prodID).value;window.location = "/_nCartAddToBasket.asp?ProductID=" + prodID + "&ProductColourID=" + colID + "&ProductSizeID=" + sizeID + "&Qty=" + qty + "&fgID=" + fgID;
}else{
alert("You must enter a numeric value in the quantity field.");}
}else{
alert("You must enter a quantity before adding to your basket.");}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我对你的问题做了一些编辑,以便让它有意义。您的文本元素不能同时为空且大于零。
这可确保文本元素的值是由一位或多位数字组成的字符串。
I edited your question a little in order to have it make some sense. Your text element cannot be both empty and greater than zero at the same time.
That makes sure that the value of the text element is a string of one or more digits.
根据您所写的内容,您可能会喜欢这样的支票
according to what you wrote, you may like a check like this one