gpt4 book ai didi

javascript - 通过单选按钮启用\禁用元素

转载 作者:行者123 更新时间:2023-11-28 12:04:20 25 4
gpt4 key购买 nike

假设,我有一些想要填写的内容,基于单选按钮,例如,如果我单击一个 radiobutton、3 个 textarea(或 输入s)变为事件状态,我可以填充它们,而“属于”其他单选按钮的文本区域变为非事件状态,我无法填充它,反之亦然。

<form>
<input type="radio" name="group1" value="1"> val1<br>

<input type="radio" name="group1" value="2" checked> val2<br>

<input type="text" value="123123" id="id1">
<input type="text" value="123123" id="id2">
<input type="text" value="123123" id="id3">
<input type="text" value="123123" id="id4">
</form>

问题是,如何使用事件 val1 单选按钮启用输入 id1,id2,id3 并使用 val2 启用 id4 并禁用 id1,id2,id3

最佳答案

试试这个 - http://jsfiddle.net/h7ZYY/

$("input:text").prop("disabled", true);
$("input:radio").on("click", function() {
$("input:text").prop("disabled", true);
$("input.group" + $(this).val()).prop("disabled", false);
});

关于javascript - 通过单选按钮启用\禁用元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11632126/

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