如何查找输入字段中的正数和负数的数量
How to find the number of positive and negative numbers are there on an input field?
我的问题是有 3 个输入文本字段和一个按钮,无论用户输入并按下按钮,警报都应该说明文本字段上有多少负数和多少正数?
这是一个工作示例 代码解释如下。
如果您想在每个文本字段中输入一个数字,然后单击告诉输入的正号和负号数的按钮,那么这是您的代码,
你的 HTML 代码,
<input id="one" type="text"/>
<input id="two" type="text"/>
<input id="three" type="text"/>
<input type="button" onclick="check();" value="check">
现在您可以按如下方式编写脚本,
function check(){
//Converting the values to integer
var x = parseInt(document.getElementById("one").value);
var y = parseInt(document.getElementById("two").value);
var z = parseInt(document.getElementById("three").value);
//Initializing the positive and negative count to 0
var posCount = 0;
var negCount = 0;
//Incrementing postive and negative count depending whether it is positive or negative
if(x>=0){
posCount++;
}else{
negCount++;
}
if(y>=0){
posCount++;
}else{
negCount++;
}
if(z>=0){
posCount++;
}else{
negCount++;
}
alert("Positive numbers: "+posCount);
alert("Negative numbers: "+negCount);
}
相关文章:
- 如何使用与单个查找字段相关的信息填充字段
- CRM Javascript使用特定字段自动填充查找值
- 在指定的td中查找输入字段的特定值
- 查找具有字段值的对象(这是一个指针)
- 查找包含子对象MongoDb和Node.js的特定字段的文档
- 使用jQuery查找输入字段
- 在MongoDB和Node.js中查找某个字段具有与对象完全相同元素的文档
- 查找Mongodb字段中出现次数最多的单词
- 我需要使用mongodb本机驱动程序来查找按时间戳字段排序的不同id
- 如何使用Javascript查找一系列隐藏输入字段的索引
- 查找对象树中特定字段值的所有出现
- MongoDB - 查找元素,其中字段等于数组中的至少一个值
- 使用 Postman 和 Javascript 在 API 方法中查找特定字段
- 查找表单和字段名称的总数
- 如何使用jQuery从数据列表中查找隐藏字段值
- 从四个输入字段中查找总计或平均值,并在另一个输入字段中显示值
- 使用在吃水线/帆中查找获取更少的字段
- JavaScript 从字段中查找值
- 从隐藏字段中查找值
- 从javascript打开CRM 2011中字段的查找对话框