我有javascript函数来控制按钮的可见性,这些按钮的设置取决于参数的值。
function checkStateDropDownLists(avaiable,selected) {
if (avaiable < 1) {
document.getElementById("btnAddHouse").style.visibility = 'hidden';
document.getElementById("btnShowDescription").style.visibility = 'hidden';
}
else {
document.getElementById("btnAddHouse").style.visibility = 'visible';
document.getElementById("btnShowDescription").style.visibility = 'visible';
}
if (selected < 1) {
document.getElementById("btnRemoveSelected").style.visibility = 'hidden';
document.getElementById('btnConfirmHouses').style.visibility = 'hidden'
}
else {
document.getElementById("btnRemoveSelected").style.visibility = 'visible';
document.getElementById('btnConfirmHouses').style.visibility = 'visible'
}
}
我在标记脚本中调用此函数
checkStateDropDownLists(document.getElementById("ReservationAvaiableHouses").length, document.getElementById("ReservationSelectedHouses").length);
元素: ReservationAvaiableHouses 和 ReservationSelectedHouses 是下拉列表,参数是每个选项的数量。以这种方式打电话没有任何结果。是格式给定参数还是这种方法调用应该在head section之外?方法的定义在头部。
Html代码
<div class="form-horizontal">
<h4>Domek</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div id="housesDropdownLists">
<div class="form-group">
@Html.Label("Rodzaje domków", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("ReservationAvaiableHouses", Model.AvaiableHouses, new { id = "ReservationAvaiableHouses" })
<input type="button" id="btnShowDescription" value="Opis" />
<div id="description" style="display:inline-flex">
</div>
</div>
</div>
<div class="form-group">
@Html.Label("Wybrane domki", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("ReservationSelectedHouses", Model.SelectedHouses, new { id = "ReservationSelectedHouses" })
<input type="button" id="btnRemoveSelected" value="Usuń zaznaczenie" onclick="handler(event)" />
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-10">
<input type="button" id="btnAddHouse" value="Dodaj domek" class="btn btn-default" />
<input type="submit" id="btnConfirmHouses" value="Potwierdź domki" class="btn btn-default" style="visibility:hidden" />
</div>
</div>
</div>