开发者

Extract value of userdefined attribute of a tag using jquery

I have input tags with a user defined attribute as:-

<input name="grp1" type="radio" myUDF="value1" />
<input name="grp1" type="radio" myUDF="value1" />开发者_开发百科;

How can i extract the value of myUDF?

The scenario is :-

$("input[name=grp1]").click(function(){
   this.attr("myUDF"); // This throws the exception Object doesnt support this prop or mehod
});


'this' is the dom object - not a jquery object therefore it does not have the attr function.

You need to create a jq object with this e.g

$(this).attr("myUDF");


you can get attribute value like that:

$("input[name=grp1]").click(function() {
    alert($(this).attr("myUDF"));
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜