我是编码新手。我有两个单选按钮。如果从它们中的任何一个中选择“是”,则必须将某个字段(此处为 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>
查询
$('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);
}
});
代码没有任何问题。
只需提供您听到点击的元素的名称。
代替:
$('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);
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句