开发者

How to access the value of a radio button that is checked using YUI?

开发者 https://www.devze.com 2023-01-29 20:00 出处:网络
i have following radio button structure ... <div id=\"test\"> <input name=\"test1\" value=\"a\" type=\"radio\">

i have following radio button structure ...

<div id="test">
  <input name="test1" value="a" type="radio">
  <input name="test1" value="b" type="radio">
  <input name="test1" value="c" type="radio">
</div>

how would i go about retrieving the value of any checked radio 开发者_JS百科button?

i have checked the YUI documentation an there is not really any good example.

I would also like to know how to get the element by input name in YUI?


In YUI 3:

var value = Y.one("#test input[name=test1]:checked").get("value");

In YUI 2:

// the null, null, null, true is optional, but returns only the first match
var input = YAHOO.util.Dom.getElementsBy(function (el) {
                return (el.name === 'test1' && el.checked);
            }, 'input', 'test', null, null, null, true);

var value = input.value;


If you have a reference to your ButtonGroup, you can do like this (in YUI 2):

var buttonGroup = new YAHOO.widget.ButtonGroup("test"); 
var button = buttonGroup.get("checkedButton");
var value = button.get('label');
0

精彩评论

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

关注公众号