Javascript 基于下拉选择的收音机选择/取消选择

Javascript 基于下拉选择的收音机选择/取消选择,javascript,html,Javascript,Html,事情是这样的: 我有3个以上选项的下拉列表,以及是/否广播组。选择选项1时,我需要设置收音机否为选中状态,选择其他选项时,设置收音机是 代码如下: <select id="exp_days" name="exp_days"> <?php foreach($this->days as $day){ echo '<option value="'.$day->days.'"';

事情是这样的:

我有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.'&nbsp;'.'DAY';
            }else{
                echo $day->days.'&nbsp;'.'DAYS';    
            } 

            if($day->price !='0.00'){
                //echo '&nbsp;-&nbsp;'.$day->price.'&nbsp;'.$par->get('unit_price');    
                echo '&nbsp;-&nbsp;'.priceFormat($day->price,$par->get('unit_price'));
            }
        echo '</option>';
    }
?>
以下是您想要的:

<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.'&nbsp;'.'DAY';
            }else{
                echo $day->days.'&nbsp;'.'DAYS';    
            } 

            if($day->price !='0.00'){
                echo '&nbsp;-&nbsp;'.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>

工作小提琴显示您想要的:

我当然不想粗鲁或其他什么,但您尝试了什么?也许您可以尝试一些javascript/JQuery,然后发布您稍后尝试的内容??除了在选择中两次使用value=1选项外,您是想在发布后设置收音机,还是使用javascript?值由php自动生成。javascript还可以
<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.'&nbsp;'.'DAY';
            }else{
                echo $day->days.'&nbsp;'.'DAYS';    
            } 

            if($day->price !='0.00'){
                echo '&nbsp;-&nbsp;'.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>