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

穿精又带淫゛_ 提交于 2019-12-08 15:22:38

问题


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 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?


回答1:


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;



回答2:


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');


来源:https://stackoverflow.com/questions/4376002/how-to-access-the-value-of-a-radio-button-that-is-checked-using-yui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!