我想这样做,只有单击单选按钮(选项3)时才会显示下拉列表,如果选择了1或2,则将其隐藏.什么是最好的方法来完成这个?我对JavaScript有一点点经验,对jQuery很少,但看起来它可能是要走的路.
谢谢你的帮助,丹
这是我现在的HTML代码:
<p class="help">Selection:</p>
<div id='buttons'>
<label><input type="radio" name="select" /> Option 1 </label>
<label><input type="radio" name="select" /> Option 2</label>
<label><input type="radio" name="select" /> Option 3</label>
</div>
<div id="list" style="display: none;">
<label>Please Select From the List:
<select>
<option>True</option>
<option>False</option>
</select>
</label>
</div>
Run Code Online (Sandbox Code Playgroud)
$(document).ready(function(){
$("[name=select]").change(function(){ // Whenever the radio buttons change
$("#list").toggle($("[name=select]").index(this)===2); // Only keep the list open when it's the last option (First option = 0, Third option = 2)
});
});
Run Code Online (Sandbox Code Playgroud)
这段代码正在运行。