1

2 つの選択ドロップダウン リストがあります。

<select name="internal_message">
<option value="yes">Yes</option>
<option value="" selected="selected">No</option>
</select>

<select name="internal_message_agent">
<option value="">Choose</option>.... etc
</select>

私が試してみました:

<select name="internal_message">
            <option value="yes" onClick="document.getElementById('internal_message_agent').disabled=!this.selected;">Yes</option>
            <option value="" selected="selected">No</option>
            </select>

しかし、それは機能しません - internal_message の選択された値"No""Yes"

4

2 に答える 2

4

各選択に ID を追加し、jquery を使用して次のように無効にします。

$('#box1').on('change', function(){
if($(this).val()==='no'){
    $('#box2').attr('disabled', 'disabled');
}else{
    $('#box2').attr('disabled', false);
}
});

http://jsfiddle.net/3MCaG/1/

于 2013-10-21T18:52:39.060 に答える
0

Javascript と HTML を使用すると、次のようになります。

<!DOCTYPE html>
<html>
<head>
</head>
<script>
function validate(){
    var b1 = document.getElementById("box1");
    var f = b1.options[b1.selectedIndex].value;
    var b2 = document.getElementById("box2");
        if(f == "no"){
        b2.disabled="disabled";
        }
    else{
    b2.disabled="";
    }
}
</script>
<select id="box1" onchange="validate()">
    <option id="yes" value="yes">Yes</option>
    <option id="no" value="no" selected="selected">No</option>
</select>

<select id="box2" disabled>
    <option></option>
    <option value="">Choose</option>
</select>
</html>
于 2013-10-21T19:20:12.040 に答える