当checkbox勾选上的时候,上面的下拉列表的值会变”admin,mote“然后显示到列表中,请问要如何写。
请高手指教。

解决方案 »

  1.   

    var html = '<option>admin</option><option>mote</option>';
    $('xxx').append(html);
      

  2.   

    $('input').click(function(){
    $(this).attr("checked")=='checked'?$('select').html($('select').html()+'<option>mote</option>'):$('select').html($('select').html().toLowerCase().replace('<option>mote</option>',''));  
    }); 
      

  3.   

    //你到底是要追加成<option>admin,mote</option>
    //还是追加成<option>admin</option><option>mote</option>
    //不管什么都简单。你可以参考 Jquery操作select  
      

  4.   


    当前选中的下拉框的值变成admin,mote ?<select id="s">
        <option value="admin">admin</option>
    </select>
    <br />
    <input id="chk" name="chk" type="checkbox" /><lable for="chk">许可追加",mote"</lable>
    <script type="javascript">
        $("#chk").unbind("change").bind("change",function(){
            var str = $("#s").text();
            if(this.checked){            
                if(!str.text(/\,mote$/i)){
                    str += ",mote";
                }
            }else{
                if(str.text(/\,mote$/i)){
                    str = str.replace(/\,mote$/i,"");
                }
            }
            $("#s>option:selected").text(str);
        });
    </script>
      

  5.   


    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script language="javascript">
    $(function(){
    $(":checkbox").change(function(){
    if($(this).is(":checked")){
    $("#selectform").append('<option value=\"moto\">mote</option>');
    }else{
    $("#selectform").html('<option value=\"admin\">admin</option>');
    }
    });
    })
    </script><select id="selectform">
        <option value="admin">admin</option>
    </select>
    <br/>
    <input type="checkbox" id="box"  />许可追加",mote"