如何将来自两个单选按钮的输入分配给单个字段?(How to assign the input from two radio buttons to a single field?)
我是编码新手。 我有两个单选按钮。 如果从它们中选择了“是”,则某个字段(此处为kouAP)必须自动设置为一个值(在本例中为0.56)。 问题是:
- 如何使两个单选按钮将值设置为单个字段?
- 如果其中一个是“是”,另一个是“否”,如何保持希望的价值? 不管点击的顺序如何。
我的JQuery没有任何意义:(
谢谢
HTML
<label for="Pre002">ccs</lable> <br /> <input type="radio" id="Pre002o" name="css" value="0"> <label for="Pre002o">none</label> <input type="radio" id="Pre002d" name="css" value="4"> <label for="Pre002d">yes</label> <br /> <label for="Pre066">mi</lable> <br /> <input type="radio" id="Pre066a" name="mi" value="0"> <label for="Pre066a">yes</label> <input type="radio" id="Pre066b" name="mi" value="1"> <label for="Pre066b">no</label> <br /> <input id="kouAP" type=“text” name="kouAP" readonly="true" placeholder="kouAP"> <label for="kouAP">at least one yes</label>
JQuery的
$('input[type=radio].css; input[type=radio].mi').click(function(e){ if ($(this).attr("id") == "Pre002d" || $(this).attr("id") == "Pre066a" ){ $("#kouAP").val(0.5677075); } else { $("#kouAP").val(0); } });
I am new in coding. I have two radio buttons. If a “yes” is selected in either from them a certain field (here kouAP) must be AUTOMATICALLY set to a value (in this case 0.56). The problems are:
- how to make both radio buttons to set the value to a single field?
- How to keep the wished value if one of the is “yes” and the other is “no”? No matter of the order of clicking.
My JQuery makes no sense :(
Thanks you
HTML
<label for="Pre002">ccs</lable> <br /> <input type="radio" id="Pre002o" name="css" value="0"> <label for="Pre002o">none</label> <input type="radio" id="Pre002d" name="css" value="4"> <label for="Pre002d">yes</label> <br /> <label for="Pre066">mi</lable> <br /> <input type="radio" id="Pre066a" name="mi" value="0"> <label for="Pre066a">yes</label> <input type="radio" id="Pre066b" name="mi" value="1"> <label for="Pre066b">no</label> <br /> <input id="kouAP" type=“text” name="kouAP" readonly="true" placeholder="kouAP"> <label for="kouAP">at least one yes</label>
JQuery
$('input[type=radio].css; input[type=radio].mi').click(function(e){ if ($(this).attr("id") == "Pre002d" || $(this).attr("id") == "Pre066a" ){ $("#kouAP").val(0.5677075); } else { $("#kouAP").val(0); } });
原文:https://stackoverflow.com/questions/47222761
满意答案
代码没有问题。
只需提供您收听点击的元素的名称即可。
更换:
$('input[type=radio].css; input[type=radio].mi').click(...);
附:
$('input').click(...);
要么:
$('input[type=radio]').click(...);
以避免将来的错误。
我建议你再次完成基础知识:)
编辑
对于第二个问题,我想这只是一个if..else的工作。 希望能帮助到你。
$('input').click(function(e){ if ($('#Pre002d').is(':checked') || $('#Pre066a').is(':checked')){ $("#kouAP").val(0.5677075); } else{ $("#kouAP").val(0); } });
There is nothing wrong with code.
Just provide the name of the element you listen the click from.
Replace:
$('input[type=radio].css; input[type=radio].mi').click(...);
With:
$('input').click(...);
or:
$('input[type=radio]').click(...);
to avoid future errors.
I just advice you to go through the basics again :)
EDIT
For the second question, I guess it's just a work around with if..else. Hope it helps.
$('input').click(function(e){ if ($('#Pre002d').is(':checked') || $('#Pre066a').is(':checked')){ $("#kouAP").val(0.5677075); } else{ $("#kouAP").val(0); } });
相关问答
更多如何将单选按钮的属性分配给复选框(How to assign Property of Radio button to a Checkbox)
Radio Buttons jQuery(Radio Buttons jQuery)
分配单选按钮的标签而不是值(Assign radio button's label instead of value)
将多个单选按钮与单个文本框关联(Associate multiple radio buttons with a single textbox)
如果未选中单选按钮,如何将隐藏字段设置为零(How to set hidden field to zero if radio buttons are not checked)
Textinput字段禁用单选按钮(Textinput field disables radio buttons)
单选按钮和一个输入字段(Radio Button and an Input field)
如何将来自两个单选按钮的输入分配给单个字段?(How to assign the input from two radio buttons to a single field?)
angularjs使用下拉和单选按钮绑定输入文本字段(angularjs bind input text field with drop down and radio buttons)
相关文章
更多Hadoop 1.2.1 单节点安装(Single Node Setup)步骤
Solr4.7---Field、CopyField、DynamicField
jquery1.4.4的radio选中项
Solr Document [null] missing required field: id 的原因
Becoming a data scientist
[转]So You Want To Be A Producer
Spring Data: a new perspective of data operations
Solr: a custom Search RequestHandler
A Great List of Windows Tools
Create a Bootable MicroSD Card
最新问答
更多FacebookSDK Corekit框架错误(FacebookSDK Corekit framework error)
给定均数向量和协方差矩阵的多元正态分布(multivariate normal distribution given mean vector and covariance matrix)
找到youtube iframe并将其替换为自定义代码(Find youtube iframe and replace it with custom code)
如何将svg形状与svg文本合并(How to merge svg shape with a svg text)
如何仅将自定义扩展限制为特定项目(How do i limit the custom extensions to specific projects only)
使用mysql显示特定国家/地区的Web内容的最佳方式(Best way to display web content for specific country using mysql)
SpeechSynthesisUtterance语言列表?(SpeechSynthesisUtterance list of languages?)
Matlab操纵边缘(Matlab manipulate edges)
创建一个通用扰流盒(Creating a universal spoiler box)
C#Excel检查单元格在VSTO中包含一个名称(C# Excel Check cell contains a name in VSTO)
Copyright ©2018 656463.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!