2013-06-04 39 views
19

我有两个单选按钮。我希望能够获得选中单选按钮的自定义属性“xmlvalue”的值。获取自定义属性的值

我试图与下面的脚本:

var userType = $("input[name=ctrl_CustomerType]:checked", this).attr('xmlvalue'); 

标记:

<input type="radio" name="ctrl_CustomerType" id="ctrl_CustomerType_1" xmltag="CustomerType" xmlvalue="existingCustomer" checked="checked"> Yes 
<br /> 
<input type="radio" name="ctrl_CustomerType" id="ctrl_CustomerType_2" xmltag="CustomerType" xmlvalue="newCustomer"> No 

Fiddle here

- 但我不断收到 “未定义”。

任何想法?

回答

29

删除您选择的情况下:

http://jsfiddle.net/NrQek/1/

var userType = $("input[name=ctrl_CustomerType]:checked").attr('xmlvalue'); 
     alert("xmlvalue is: " + userType); 
+0

我不知道我在想什么。非常感谢。它按预期工作。 – Meek

3

您的选择是错误的。

输入元素不是a元素的孩子在那里你点击,所以你不能传递this作为上下文来选择

var userType = $("input[name=ctrl_CustomerType]:checked").attr('xmlvalue'); 

演示:Fiddle

相关问题