gpt4 book ai didi

javascript - 如何禁用带有单选按钮的组合框(javascript)

转载 作者:行者123 更新时间:2023-11-30 18:18:57 25 4
gpt4 key购买 nike

我的 HTMl 中有 3 个单选按钮和 3 个不同的组合框。我希望 Crtl 通过单选按钮启用/禁用组合框。例如,当我点击 G1 单选按钮时,只有 g1 组合框被启用,其他的被禁用。我如何使用 JS !?

<input type="radio" name="g1" value="g1"> G1
<input type="radio" name="g2" value="g2"> G2
<input type="radio" name="g3" value="g3"> G3


<select name="g1">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>

<select name="g2">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>

<select name="g3">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>

最佳答案

在 jQuery 中尝试这段代码,效果很好:

<script type="text/javascript" language="javascript">
$(document).ready(function(){
$('.radio').click(function(){
$('.radio').not(this).removeAttr("checked");
var id="select_"+$(this).attr('id');
$('select').removeAttr("disabled");
$('select').not("#"+id).attr('disabled','true');
});
});
</script>

html:

<input type="radio" name="g1" value="g1" class="radio" id="g1"> G1
<input type="radio" name="g2" value="g2" class="radio" id="g2"> G2
<input type="radio" name="g3" value="g3" class="radio" id="g3"> G3


<select name="g1" id="select_g1">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
</select>

<select name="g2" id="select_g2">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
</select>

<select name="g3" id="select_g3">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
</select>

JSFIDDLE:* http://jsfiddle.net/Xbcvh/ *

关于javascript - 如何禁用带有单选按钮的组合框(javascript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12560043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com