【发布时间】:2018-05-15 03:21:31
【问题描述】:
直截了当,我的问题是,如何在 copy_Power_Plant() 中放置 if else 语句以检测其值为 Yes、No 或 Unclear。 我这样做的方式是行不通的。我的代码在下面。
.................................................. .....................
忽略这里,我需要输入许多详细信息,以便 stackoverflow 允许我发布。这太烦人了。
<!DOCTYPE html>
<html>
<body>
<script>
function copy_Type_Mount() {
document.getElementById("label_Type_Mount").innerHTML = document.getElementById("Type_Mount").value+" AC Units "}
function copy_No_Units() {
document.getElementById("label_No_Units").innerHTML = document.getElementById("No_Units").value}
function copy_Size(){
document.getElementById("label_Size").innerHTML = document.getElementById("Size").value+ " HP "}
//below this function is the problem
function copy_Power_Plant(){
var pp=document.getElementById("Power_Plant").value;
if(pp=='Yes'){
document.getElementById("label_Power_Plant").innerHTML ='+ Power Plant'}}
</script>
<font id="label_No_Units"></font> <font id="label_Type_Mount"></font><font id="label_Size"></font><font id="label_Power_Plant"></font><br>
<p1>Type of Mount:</p1><br>
<select id="Type_Mount" name="Type_Mount" onchange="copy_No_Units();copy_Type_Mount();copy_Size();copy_Power_Plant();" required>
<option value="Wall Mount">Wall Mount</option>
<option value="Ceiling Mount">Ceiling Mount</option>
</select><br><br>
<p1>Number of Units:</p1><br>
<select id="No_Units" name="No_Units" onchange="copy_No_Units();copy_Type_Mount();copy_Size();copy_Power_Plant();" required>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
<br>
<br>
<p1>Size (H/P):</p1><br>
<select id="Size" name="Size" onchange="copy_No_Units();copy_Type_Mount();copy_Size();copy_Power_Plant();" required>
<option value="1">1</option>
<option value="1.5">1.5</option>
<option value="2">2</option>
<option value="2.5">2.5</option>
</select>
<br>
<br>
<p1>Power Plant Installation Required?</p1><br>
<select id="Power_Plant" name="Power_Plant" onchange="copy_No_Units();copy_Type_Mount();copy_Size();copy_Power_Plant();" required>
<option value="Yes">Yes</option>
<option value="No">No</option>
<option value="Unclear">Unclear</option>
</select>
<br>
<br>
</body>
</html>
【问题讨论】:
-
If..else statement inside javascript function not working- 好吧,你没有if..else你只有if所以,难怪if..else不起作用 -
@JaromandaX 这不是重点,不要那么挑剔.. 我写了 if 语句,但它不起作用.. 所以我没有写 else。
-
显然
pp不是Yes- 你接受了一个回答 完全相同
标签: javascript html function if-statement