2014-09-10 51 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