我对javascript很陌生。我阅读了此链接并尝试对其进行自定义,但它不起作用:Disable an input field if second input field isfilled
我想让人们在两个选项-城市和邮政编码之间切换。我想启用他们最后选择的任何字段并禁用另一个。例如,如果他们在邮政编码选项卡上并按下提交按钮,则邮政编码中的任何输入都会被提交,而不是城市,反之亦然。
html是:
<ul class="tabs">
<li><a class="border-radius top med" href="#city">City</a></li>
<li><a class="border-radius top med" href="#zipcode">Zipcode</a></li>
</ul>
<div id="city"><label class="IDX-advancedText">City</label>
<select id="aht-home-city" name="city[]" class="IDX-select " autocomplete="off">
<option value="2115">Austin</option>
<option value="2718">Bartlett</option>
</div>
<div id="zipcode"><label class="IDX-advancedText">Zipcode</label>
<input class="IDX-advancedBox IDX-advWildText" id="IDX-aw_zipcode" type="text"
maxlength="255" name="aw_zipcode" value="" /></div>
脚本是:
var dis1 = document.getElementById("city");
dis1.onchange = function () {
if (this.value != "" || this.value.length > 0) {
document.getElementById("zipcode").disabled = true;
}
}
var dis2 = document.getElementById("zipcode");
dis1.onchange = function () {
if (this.value != "" || this.value.length > 0) {
document.getElementById("city").disabled = true;
}
}
很感谢任何形式的帮助!该网站是http://austinhometeam.staging.wpengine.com/joyce-newsletter/