ai didi

javascript - jquery 单选按钮单击和更改功能不起作用

转载 作者:行者123 更新时间:2023-12-02 16:01:01 24 4
gpt4 key购买 nike

我想根据单选按钮值隐藏和显示 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/

24 4 0
文章推荐: javascript - 有什么好的建议可以提醒/提醒用户在网页上编辑字段后保存吗?
文章推荐: kubernetes - 使用 Helm 安装 Horizo​​ntalPodAutoscaler (HPA)
文章推荐: html - Bootstrap 5 模态页脚左右对齐
文章推荐: javascript - 使用 Google Maps API 查找距用户邮政编码最近的酒吧
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com