我有这个示例代码,其中显示的数据随着单选按钮选择的改变而改变:
http://bl.ocks.org/juan-cb/1984c7f2b446fffeedde
我想插入两组单选按钮而不是一组,所以我将这些行添加到代码中:
<form>
<label><input type="radio" name="region" id="region" value="North" checked> North</label>
<label><input type="radio" name="region" id="region" value="South"> South</label>
<label><input type="radio" name="region" id="region" value="East"> East</label>
<label><input type="radio" name="region" id="region" value="West"> West</label>
</form>
<form>
<label><input type="radio" name="dataset" id="dataset" value="2009" checked> 2009</label>
<label><input type="radio" name="dataset" id="dataset" value="2010"> 2010</label>
<label><input type="radio" name="dataset" id="dataset" value="2011"> 2011</label>
<label><input type="radio" name="dataset" id="dataset" value="2012"> 2012</label>
<label><input type="radio" name="dataset" id="dataset" value="2013"> 2013</label>
<label><input type="radio" name="dataset" id="dataset" value="2014"> 2014</label>
</form>
我想更改代码,以便在选择两个单选按钮时发生事件,例如&#34; North&#34; AND&#34; 2010&#34;。
问题是我不知道如何获取两个单选按钮表单的选定值以便在此处应用:
d3.selectAll("input")
.on("change", selectDataset);
function selectDataset()
{
var value = this.value;
if (value == "total") && (value == "North")
{
change(datasetTotal);
}
(...)
}
例如。
答案 0 :(得分:0)
var selectedRegion = d3.select('input[name=region]:checked').attr('value');
var selectedDataset = d3.select('input[name=dataset]:checked').attr('value')
if (selectedDataset == "total") && (selectedRegion == "North") {
...
}