我正在开发一个测试页面,用户可以在其中配置播种机。 计算等工作正常。但是当使用单选按钮时,条件的顺序会影响它们。
当选择底部否时,用户不应该选择车轮脚<>好 当选择Bottom yes时,用户不应该选择车轮脚&gt;行
但是不能同时选择脚或轮子。 因此,当选择轮子是,然后选择脚是&gt;车轮必须设置为否>行
但另一种方式是当选择了脚是,并且轮子是,脚本无法(由于条件的顺序?)将脚设置为否?
有什么建议吗?
<script type="text/javascript">
function calculatie()
{
// very much code
// Totaalprijs met of zonder pootjes
if(document.getElementById('feet_no').checked)
{
document.getElementsByName('kosten_inkoop')[0].value = (document.getElementsByName('kosten_inkoop')[0].value);
}
else if(document.getElementById('feet_yes').checked)
{
document.getElementsByName('kosten_inkoop')[0].value = ((document.getElementsByName('kosten_inkoop')[0].value * 1) + (document.getElementsByName('kosten_pootjes')[0].value * 1)).toFixed( 2 );
document.getElementById('wheel_no').checked = true;
}
// Totaalprijs met of zonder wieltjes
if(document.getElementById('wheel_no').checked)
{
document.getElementsByName('kosten_inkoop')[0].value = (document.getElementsByName('kosten_inkoop')[0].value);
}
else if(document.getElementById('wheel_yes').checked)
{
document.getElementsByName('kosten_inkoop')[0].value = ((document.getElementsByName('kosten_inkoop')[0].value * 1) + (document.getElementsByName('kosten_wieltjes')[0].value * 1)).toFixed( 2 );
document.getElementById('feet_no').checked = true;
}
}
</script>
<tr>
<td>Bottom</td>
<td>No <input type="radio" name="bottom" onChange="calculatie()"
onfocus="document.getElementById('bottom').style.display='block';document.getElementById('basis').style.display='none';"
onblur="document.getElementById('bottom').style.display='none';document.getElementById('basis').style.display='block';"
value="no" id="bottom_no" checked="checked">
<input type="radio" name="bottom" onChange="calculatie()"
onfocus="document.getElementById('bottom').style.display='block';document.getElementById('basis').style.display='none';"
onblur="document.getElementById('bottom').style.display='none';document.getElementById('basis').style.display='block';"
value="yes" id="bottom_yes" > Yes</td>
<td><div id="dim_top">Dim from top <input type="text" name="bottom_dim" size="2" onChange="calculatie()"
onfocus="document.getElementById('bottom_dim').style.display='block';document.getElementById('basis').style.display='none';"
onblur="document.getElementById('bottom_dim').style.display='none';document.getElementById('basis').style.display='block';"
value="" /> cm </div></td>
</tr>
<tr>
<td>Feet</td>
<td>No <input type="radio" name="feet" onChange="calculatie()"
onfocus="document.getElementById('feet').style.display='block';document.getElementById('basis').style.display='none';"
onblur="document.getElementById('feet').style.display='none';document.getElementById('basis').style.display='block';"
value="no" id="feet_no" checked="checked">
<input type="radio" name="feet" onChange="calculatie()"
onfocus="document.getElementById('feet').style.display='block';document.getElementById('basis').style.display='none';"
onblur="document.getElementById('feet').style.display='none';document.getElementById('basis').style.display='block';"
value="yes" id="feet_yes" > Yes</td>
</tr>
<tr>
<td>wheel</td>
<td>No <input type="radio" name="wheel" onChange="calculatie()"
onfocus="document.getElementById('wheel').style.display='block';document.getElementById('basis').style.display='none';"
onblur="document.getElementById('wheel').style.display='none';document.getElementById('basis').style.display='block';"
value="no" id="wheel_no" checked="checked">
<input type="radio" name="wheel" onChange="calculatie()"
onfocus="document.getElementById('wheel').style.display='block';document.getElementById('basis').style.display='none';"
onblur="document.getElementById('wheel').style.display='none';document.getElementById('basis').style.display='block';"
value="yes" id="wheel_yes" > Yes</td>
</tr>
答案 0 :(得分:0)
尝试下面的脚本,它应该工作。稍作改动,
<script type="text/javascript">
function calculatie()
{
// very much code
// Totaalprijs met of zonder pootjes
if(document.getElementById('feet_no').checked)
{
document.getElementsByName('kosten_inkoop')[0].value = (document.getElementsByName('kosten_inkoop')[0].value);
}
else if(document.getElementById('feet_yes').checked && document.getElementById('wheel_yes').checked)
{
document.getElementsByName('kosten_inkoop')[0].value = ((document.getElementsByName('kosten_inkoop')[0].value * 1) + (document.getElementsByName('kosten_pootjes')[0].value * 1)).toFixed( 2 );
document.getElementById('wheel_no').checked = true;
}
// Totaalprijs met of zonder wieltjes
if(document.getElementById('wheel_no').checked)
{
document.getElementsByName('kosten_inkoop')[0].value = (document.getElementsByName('kosten_inkoop')[0].value);
}
else if(document.getElementById('wheel_yes').checked)
{
document.getElementsByName('kosten_inkoop')[0].value = ((document.getElementsByName('kosten_inkoop')[0].value * 1) + (document.getElementsByName('kosten_wieltjes')[0].value * 1)).toFixed( 2 );
document.getElementById('feet_no').checked = true;
}
}
</script>
&#13;
if条件的顺序正在产生问题。当&#34; Wheel Yes&#34;时,单选按钮被切换。单击,但由于if条件,它会恢复。