我想根据单选按钮值隐藏和显示 div。 HTML 代码是,
<div id="share_to_others">
<input type="radio" value="33" id="fx_sharepl_type" name="fx_sharepl_type">
<input type="radio" value="22" id="fx_sharepl_type" name="fx_sharepl_type">
<input type="radio" value="11" id="fx_sharepl_type" name="fx_sharepl_type">
</div>
我尝试过的 jquery 代码是,
$("#share_to_others input[name='fx_sharepl_type']").click(function () {
alert("test");
});
$("#share_to_others input[name='fx_sharepl_type']").change(function () {
alert("test");
});
$("#fx_sharepl_type").change(function () {
alert("asdas");
});
$("input[name=fx_sharepl_type]:radio").change(function () {
alert("click fired");
});
$(document).on('change', 'input:radio[name=fx_sharepl_type"]', function (event) {
alert("click fired");
});
其中许多来自 jsfiddle 工作演示,但不适合我,我不知道为什么。 我做错了什么吗?
最佳答案
您必须为每个单选按钮提供唯一的 id,然后像这样进行操作。
$("#r1, #r2, #r3").change(function () {
关于javascript - jquery 单选按钮单击和更改功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31206463/