2012-09-30 101 views
0

Gidday在點擊提交按鈕之前獲取按鈕集數據?

,只是學習jQuery UI的,並取得了今天的一些很好的進展,但搞清楚的時候如何讓所選擇的按鈕的ID在buttonset提交表單之前已經得到難倒。

我知道如何使AJAX POST工作,一旦我得到的選擇按鈕的ID。

第一部分是如何完成的?

這裏是我的jQuery:

$("#pi").buttonset(); 


    $("#req1").dialog({   

     resizable: false, 
     height:350, 
     minWidth: 310, 
     modal: true, 
     buttons: { 
      "Send request": function() { 


        //what goes here to retrieve the ID of the selected button? 


       $(this).dialog("close"); 
      }, 
      Cancel: function() { 
       $(this).dialog("close"); 
      } 
     } 
    }); 

我的形式...

<div id="req1" title="make your selection:"> 

<form> 
<div id="pi"> 
    <input type="radio" id="p1" name="pi" /><label for="p1">3</label> 
    <input type="radio" id="p2" name="pi" /><label for="p2">2</label> 
    <input type="radio" id="p3" name="pi" /><label for="p3">1</label> 
    <input type="radio" id="p4" name="pi" checked="checked" /><label for="p4">0</label> 
    <input type="radio" id="p5" name="pi" /><label for="p5">1</label> 
    <input type="radio" id="p6" name="pi" /><label for="p6">2</label> 
    <input type="radio" id="p7" name="pi" /><label for="p7">3</label> 
</div> 

感謝您的時間和幫助。

回答

0

試試這個:

var id = $('#pi input[name=pi]:checked').attr('id'); 
+0

完美Shvetusya - 非常感謝你。 – Shaun