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