这就是事情:
我有3个以上选项的下拉列表,以及是/否无线电组。我需要的是在选择选项1时设置无线电“否”,在选择其他选项时设置无线电“是”。
以下是代码:
<select id="exp_days" name="exp_days">
<?php
foreach($this->days as $day){
echo '<option value="'.$day->days.'"';
if($day->days==$exp_days){
echo ' SELECTED ';
}
echo '>';
if($day->days==1){
echo $day->days.' '.'DAY';
}else{
echo $day->days.' '.'DAYS';
}
if($day->price !='0.00'){
//echo ' - '.$day->price.' '.$par->get('unit_price');
echo ' - '.priceFormat($day->price,$par->get('unit_price'));
}
echo '</option>';
}
?>
<input type="radio" name="p_first" value="1" checked="checked"/><label>YES</label>
<input type="radio" name="p_first" value="0"/><label>NO</label>
答案 0 :(得分:1)
这是你想要的:
<script>
function change(select){
if(select.selectedIndex === 0){
document.getElementById('radio1').checked=true;
document.getElementById('radio2').checked=false;
}else{
document.getElementById('radio2').checked=true
document.getElementById('radio1').checked=false;
}
}
</script>
<select id="exp_days" name="exp_days" onchange="change(this)">
<?php
foreach($this->days as $day){
echo '<option value="'.$day->days.'"';
if($day->days==$exp_days){
echo ' SELECTED ';
}
echo '>';
if($day->days==1){
echo $day->days.' '.'DAY';
}else{
echo $day->days.' '.'DAYS';
}
if($day->price !='0.00'){
echo ' - '.priceFormat($day->price,$par->get('unit_price'));
}
echo '</option>';
}
?>
<input type="radio" name="p_first" id="radio1" value="1" checked="checked"/><label>YES</label>
<input type="radio" name="p_bg" id="radio2" value="0"/><label>NO</label>
显示您想要的工作小提琴:http://jsfiddle.net/vDHV7/1/