Javascript 在JQuery中未检测到单选按钮更改

Javascript 在JQuery中未检测到单选按钮更改,javascript,jquery,radio,Javascript,Jquery,Radio,有人能帮我一下吗?为什么没有检测到更改 这是我的单选按钮表格- <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"

有人能帮我一下吗?为什么没有检测到更改

这是我的单选按钮表格-

<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>

请使用下面的
change

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

});
$(文档).ready(函数(){
$('form#AskMethod[type=radio][name=method]')。在('change',function()上{
if($(this).is(':checked'){//仅为选中单选按钮添加条件
开关($(this.val()){
案例“TextMethod”:
警报(“文本”);
打破
案例“ImageMethod”:
警报(“图像”);
打破
}
}
}).change();//添加手动调用更改事件以在加载时调用更改事件
});

选择选项:
键入文本
上传图像
需要简单的更改

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


$(文档).ready(函数(){
$('label')。在('click',function()上{
开关($(this).find('input[type=“radio”][name=“method”]').val()){
案例“TextMethod”:
警报(“文本”);
打破
案例“ImageMethod”:
警报(“图像”);
打破
}
});
});
选择选项:
键入文本
上传图像
$('input#AskMethod[type=radio][name=method])
更改为
$('form#AskMethod[type=radio][name=method])
,因为在您的代码中,您在输入中查找id为
AskMethod
的元素,这是错误的
$('input[type="radio"][name="method"]').on('change', function () {           
        switch ($(this).val()) {
            case 'TextMethod':
                alert("Text");
                break;
            case 'ImageMethod':
                alert("Image");
                break;
        }
    });