【问题标题】:get value of checked radio button using d3.js使用 d3.js 获取选中的单选按钮的值
【发布时间】:2016-03-14 15:04:38
【问题描述】:

我有以下表格:

<form>
    <input type="radio" name="group-stack" value="grouped" checked>grouped<br>
    <input type="radio" name="group-stack" value="stacked">stacked
</form>

我想使用 d3 获取当前选中的单选按钮的值。

以下尝试均未成功:

var val = d3.select('input[name="group-stack"]').checked; //undefined
var val = d3.select('input[name="group-stack"][checked]')[0][0].value //always 'grouped' regardless of which radio is selected

【问题讨论】:

    标签: javascript d3.js css-selectors


    【解决方案1】:

    试试这个

    d3.select('input[name="group-stack"]:checked').node().value
    

    【讨论】:

    • 我比 [0][0] 更喜欢 .node()。我很高兴你回答。谢谢。
    【解决方案2】:

    我参加聚会有点晚了,但是,FWIW,这是纯粹的 d3 方式:

    d3.select('input[name="group-stack"]:checked').property("value");
    

    【讨论】:

      【解决方案3】:

      啊……明白了

      d3.select('input[name="group-stack"]:checked')[0][0].value
      

      【讨论】:

        猜你喜欢
        • 2011-04-21
        • 2012-07-18
        • 1970-01-01
        • 2016-11-09
        • 1970-01-01
        • 2016-08-30
        • 1970-01-01
        相关资源
        最近更新 更多