javascript - 编辑相同div但多个跨度内的按钮

时间:2013-05-07 02:26:13

标签: javascript html yui

我正在寻找一种解决方案,每次单击按钮时,将多个按钮更改为未选中状态。这是div

<div id="season" align="center">
     <span class="yui-button yui-radio-button yui-button-checked yui-radio-button-checked" id="season">
          <span class="first-child">
               <button type="button" id="season-button">Spring</button>
          </span>
     </span>
     <span class="yui-button yui-radio-button" id="season">
          <span class="first-child">
                <button type="button" id="season-button">Summer</button>
          </span>
     </span>
     <span class="yui-button yui-radio-button" id="season">
          <span class="first-child">
               <button type="button" id="season-button">Fall</button>
          </span>
     </span>
     <span class="yui-button yui-radio-button" id="season">
          <span class="first-child">
               <button type="button" id="season-button">Winter</button>
          </span>
     </span>
</div>

我可以通过以下方式访问按钮:

var groupName = document.getElementById(id).getElementsByTagName("button")

但如果我尝试

    for (i = 0; i < groupName.length; i++) {
         groupName[i].set("checked", false);
    }

没有任何反应

非常感谢任何帮助!

谢谢!

1 个答案:

答案 0 :(得分:1)

Checked不是<button>的有效属性。如果你想要像收音机这样的按钮,请使用<input type="radio">并将它们设置为按钮。请查看the official YUI Grouped Button example了解如何执行此操作。