javascript - JQuery 中未检测到单选按钮更改

标签 javascript jquery radio-button

有人可以帮我吗,为什么没有检测到更改

这是我的单选按钮表单 -

<form style = "padding:10px; margin:5px;" id="AskMethod">
    Select Option:
    <input type="radio" name="method" value ="TextMethod" checked = "checked">Type text
    <input type="radio" name="method" value ="ImageMethod">Upload Image
</form>

这是我的 jquery 例程 -

$(document).ready(function() {
    $('input [type=radio][name=method]').on('change', function() {
        switch ($(this).val()) {
            case 'TextMethod':
                alert("Text");
                break;
            case 'ImageMethod':
                alert("Image");
                break;
        }
    });
});

最佳答案

请使用更改如下

$('form#AskMethod [type=radio][name=method]').change(function() {
 switch($(this).val()) {
     case 'TextMethod':
         alert("Text");
         break;
     case 'ImageMethod':
         alert("Image");
         break;

});

关于javascript - JQuery 中未检测到单选按钮更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37759803/

相关文章:

javascript - 如何更改以 javascript/css 中的特定字符开头的行的颜色?

javascript - jQuery 用动画改变图像并等待它触发超链接

javascript - 以非名称的形式验证 radio 元素

android - 突出显示选定的微调项

javascript - 如何设置firebase数据库安全规则?

javascript - 焦点不适用于文本区域

javascript - 将 <div> 元素内的数字输入转换为人类可读的日期

javascript - 无法调用 setInterval 两次

javascript - Firefox 和 Chrome 中的字体高度不同

c# - 将单选按钮绑定(bind)到枚举属性