以JavaScript形式输入流程编号
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了以JavaScript形式输入流程编号,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2310字,纯文字阅读大概需要4分钟。
内容图文
![以JavaScript形式输入流程编号](/upload/InfoBanner/zyjiaocheng/669/9e0a683bf1814866ba9499fb90490283.jpg)
我正在建立一个允许计算Bishop得分:https://jsfiddle.net/molecoder/zv2kww5a/3/的表格.
如您所见,用户不需要提交任何表格即可显示Bishop得分值.
在第一阶段,所有表单输入都是使用radio类型的输入构建的,如下图所示:
好吧,现在该实现存在一个问题…用户需要能够在膨胀中写一个数字(0到10之间),如下图所示:
这句话,需要一种更有效的方法.我要输入的最大和最小输入数字定义为0到10之间,最多允许两个小数位(step =“.01”).该部分中的HTML代码已修改为:
<label><b>Dilation</b></label><br/>
<input type="number" id="selecteddilation" min="0" max="10" step=".01" name="selecteddilation" value="2"/><br/>
我可以使用输入id来获取JavaScript中输入的值,例如:
var dilation = document.getElementById('selecteddilation').value;
当前代码可以在这里看到:https://jsfiddle.net/molecoder/00Lsx5mq/16/
getDilation()函数如何返回该输入?
// getDilation() finds the points based on the dilation.
// Here, we need to take user's the selection from radio button selection
function getDilation()
{
var dilationPoints=0;
//Get a reference to the form id="bishopform"
var theForm = document.forms["bishopform"];
//Get a reference to the dilation the user Chooses name=selecteddilation":
var selectedDilation = theForm.elements["selecteddilation"];
//Here since there are 4 radio buttons selectedDilation.length = 4
//We loop through each radio buttons
for(var i = 0; i < selectedDilation.length; i++)
{
//if the radio button is checked
if(selectedDilation[i].checked)
{
//we set dilationPoints to the value of the selected radio button
//i.e. if the user choose the 0 cm we set it to 0
//by using the dilation array
//We get the selected Items value
//For example dilation["Round11".value]"
dilationPoints = dilation[selectedDilation[i].value];
//If we get a match then we break out of this loop
//No reason to continue if we get a match
break;
}
}
//We return the dilationPoints
return dilationPoints;
}
解决方法:
这是从该输入字段中检索数值的最直接方法:
function getDilation()
{
return parseFloat(document.querySelector('#selecteddilation').value);
}
请注意此处使用parseFloat().在用于计算结果的每个函数中,您都将返回一个字符串.强烈建议您将这些字符串适当地转换为整数/浮点数,以便数学运算符不会自动为您执行此操作.
您可以使用parseInt()或一元运算符来完成整数操作.
编辑
为了回答有关不更新结果的问题,您还需要包括一个事件侦听器:
onchange="calculateTotalBishop()" //in style of your other listeners
HTML元素.
内容总结
以上是互联网集市为您收集整理的以JavaScript形式输入流程编号全部内容,希望文章能够帮你解决以JavaScript形式输入流程编号所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。