所以我不知道如何继续使用onchange函数来填充它所连接的单选按钮div,因为我不熟悉JavaScript的工作方式,因为我尝试在JavaScript中粘贴HTML。 ..表格单选按钮应该用复选框填充其连接的div,而视图单选按钮应该是div为空。 Codepen http://codepen.io/MarkBond/pen/JdOZaw?editors=101 BTW这是在bootstrap中完成的
JAVASCRIPT:
function changeSelection() {
if (document.getElementById("selectionTables").checked) {
document.getElementById("dropdownMenuSelect").innerHTML = "Tables";
document.getElementById("populateCheckBoxes").innerHTML = "";
} else {
document.getElementById("dropdownMenuSelect").innerHTML = "Views";
document.getElementById("unpopulateCheckBoxes").innerHTML = "";
}
}
HTML:
这不是代码中的任何地方,因为我不知道在哪里放它:/
<div class="checkbox">
<label>
<input type="checkbox" id="selectionCondition" />Condition
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" id="selectionDistribution" />Distribution
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" id="selectionProgram" />Program
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" id="selectionTreatment" />Treatment
</label>
</div>
这里有收音机按钮和停机:
<form role="form">
<div class="row">
<div class="radio col-xs-2" id="populateSelection" onchange="changeSelection()">
<label>
<input type="radio" name="optradio" id="selectionTables" />Use Tables
</label>
<label>
<input type="radio" name="optradio" id="selectionViews" />Use Views
</label>
</div>
<div class="dropdown col-xs-10">
<!--DROPDOWN BUTTON-->
<button class="btn btn-default dropdown-toggle btn-xs btn-orange" type="button" id="dropdownMenuSelect" data-toggle="dropdown" aria-expanded="true" style="margin-top:10px">
Tables
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenuSelect">
<!--DROPDOWN MENU-->
<li role="presentation"><a role="menuitem" tabindex="-1" class="link-no-jump" href="#graphOneChart">Chart</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" class="link-no-jump" href="#graphOneData">Data</a></li>
</ul>
</div>
</div>
<div class="row" id="populateCheckBoxes"></div>
<div class="row" id="unpopulateCheckBoxes"></div>
</form>
答案 0 :(得分:0)
div没有改变,所以onchange
不起作用。试试这个:
<label>
<input type="radio" name="optradio" id="selectionTables" onchange="changeSelection()" />Use Tables
</label>
<label>
<input type="radio" name="optradio" id="selectionViews" onchange="changeSelection()"/>Use Views
</label>