我遇到了使下面的代码工作的问题......我想要发生的是当用户选择select标签下的特定选项时,将显示smalljobsite div。任何帮助表示赞赏。
这是我的JS:
<script type="text/javascript">
<!--Start of displaying Small Jobsite form if 1-3 staff has been selected-->
function showSmallJobsite(small){
if(small.value == 3)
document.getElementById('smalljobsite').style.display = "block";
<!--End of displaying Small Jobsite form if 1-3 staff has been selected-->
</script>
这是我的HTML:
<div class="fieldcontainer">
<label>Number of users on site:</label>
<select id="numberofstaff" onchange="showSmallJobsite(this)">
<option value="0">--Select--</option>
<option id="staffnumberthree" value="3">1-3</option>
<option id="staffnumberseven" value="7">4-7</option>
<option id="staffnumbereight" value="8">8+</option>
</select>
<br>
<br>
</div>
<!--This is the start of the Small Jobsite section of the form-->
<div id="smalljobsite" style="display:none;">
<div class="fieldcontainer">
<label>Plan Table?:</label>
<select name="plan_table" required>
<option>--Select--</option>
<option>Yes</option>
<option>No</option>
<select>
</div>
<br><br>
<div class="fieldcontainer">
<label>E-mail:</label>
<select name="dslcablesmall" required>
<option>--Select--</option>
<option>DSL/Cable</option>
<option>LTE Only</option>
</select>
</div>
</div>
我会猜测我错过了一些非常简单的事情,就像往常一样......但我现在作为最后的手段来找你们。谢谢!
答案 0 :(得分:1)
首先,对JS的评论是//
而不是<!-- -->
。
其次,您的功能尚未关闭括号}
。
<script type="text/javascript">
// Start of displaying Small Jobsite form if 1-3 staff has been selected
function showSmallJobsite(small){
if(small.value == 3)
document.getElementById('smalljobsite').style.display = "block";
}
// End of displaying Small Jobsite form if 1-3 staff has been selected
</script>
第三,你必须做一个else语句,隐藏是否选择了其他东西。 示例:我选择3,显示项目。接下来,我选择2无附加(必须隐藏)