2014-09-10 57 views
6

我有以下的HTML變了,以HAML:獲取數據從單選按鈕屬性與jQuery

%input#insurance_isp_payment{ checked: "checked", type: "radio", name: "insurance_isp_payment", price: 27.22, value: "single"} 
27,22 € 

現在我想從單選按鈕,選中這個價格值。我試過類似的東西:

$('input[name=insurance_isp_payment]:checked').data("price") 

但是這不行。我怎麼解決這個問題?

回答

11

試試這個:而不是data()使用attr()來獲得價格值。

var price = $('input[name="insurance_isp_payment"]:checked').attr("price"); 
alert(price); 
+0

非常快的答案! – 2014-09-10 09:39:34

+0

高興地幫助你:) – 2014-09-10 09:40:00

+0

讓我的下午! – 2017-11-28 20:09:54