繁体   English   中英

带有单选按钮的jQuery不起作用

[英]JQuery with radio buttons not working

我正在创建“我的帐户”页面,这是一个较大项目的一部分。 我正在使用jquery获取有关用户选择了哪个单选按钮的数据。 我不知道为什么它不起作用,我相信问题在于用来指示单击单选按钮时的jQuery。

JQUERY:

$("input[name=currentTree]").on('change',function(){
        var currentTreeId = $(this).val();
        alert ('data:' + currentTreeId);
         $.post('selectTree.php',{currentTreeId:currentTreeId} ,function(data,status){

                alert(data + ' is the current tree');

            }); 

    });




       $("input[type=radio][name=currentTree]").change(function(){
        var currentTreeId = $(this).val();
        alert ('data:' + currentTreeId);
         $.post('selectTree.php',{currentTreeId:currentTreeId} ,function(data,status){

                alert(data + ' is the current tree');

            }); 

    });

尝试这个:

 $('input[type=radio][name=currentTree]').change(function() { if ($(this).val() == 'typeA') { alert("Got Type A Radio"); } else if ($(this).val() == 'typeB') { alert("Got Type B Radio"); } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <label for="typea">Type A</label><input id="typea" type="radio" name="currentTree" value="typeA"> <label for="typeb">Type B</label> <input id="typeb" type="radio" name="currentTree" value="typeB"> 

$("input[name=currentTree]").on('change', function(){
   ...      
});

示例: https//jsfiddle.net/b80sa4kx/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM