首先,我正在尝试制作一个gpa计算器,这是我的javascript:
<script>
var option_choose = document.createElement("option");
option_choose.innerHTML = "Choose...";
option_choose.value = -1;
var c1 = document.createElement("option");
c1.innerHTML = "Math Standard 9"
c1.value = 0;
var c2 = document.createElement("option");
c2.innerHTML = "Math Higher 9"
c2.value = 0.5;
var c3 = document.createElement("option");
c3.innerHTML = "English 9"
c3.value = 0;
var c4 = document.createElement("option");
c4.innerHTML = "History 9"
c4.value = 0;
var c5 = document.createElement("option");
c5.innerHTML = "Science 9";
c5.value = 0;
var l1 = document.createElement("option");
l1.innerHTML = "Japanese";
l1.value = 0;
var l2 = document.createElement("option");
l2.innerHTML = "French";
l2.value = 0;
var e1 = document.createElement("option");
e1.innerHTML = "Adv. Computers";
e1.value = 0;
$(".core_subjects").append(option_choose,c1,c2,c3,c4,c5);
$(".language_subjects").append(option_choose,l1,l2);
$(".elective_subjects").append(option_choose,e1);
</script>
在我的HTML中,我有:
<div id="subject_name">
<h4>Class</h4>
<select id="core1" class="core_subjects">
<option value="-1">Choose...</option>
</select>
<br/>
<select id="core2" class="core_subjects">
<option value="-1">Choose...</option>
</select>
<br/>
<select id="core3" class="core_subjects">
<option value="-1">Choose...</option>
</select>
<br/>
<select id="core4" class="core_subjects">
<option value="-1">Choose...</option>
</select>
<br/>
<select id="language" class="language_subjects">
<option value="-1">Choose...</option>
</select>
<br/>
<select id="elective1" class="elective_subjects">
<option value="-1">Choose...</option>
</select>
<br/>
<select id="elective2" class="elective_subjects">
<option value="-1">Choose...</option>
</select>
<br/>
<select id="elective3" class="elective_subjects">
<option value="-1">Choose...</option>
</select>
<br/>
<select id="elective4" class="elective_subjects">
<option value="-1">Choose...</option>
</select>
<br/>
</div>
所以基本上,当有人点击按钮时,javascript会运行,并且在每个选择中,应该首先是“选择...”选项,然后是类列表。
但出于某种原因,在使用#core4和#language的两个选项中,“选择...”不会出现。它出现在所有其他人身上。
答案 0 :(得分:0)
您应该option_choose
时option_choose_c
。错误控制台中显示此错误。
工作小提琴:http://jsfiddle.net/bUh9E/
$(".core_subjects").append(option_choose_c,c1,c2,c3,c4,c5);
$(".language_subjects").append(option_choose_c,l1,l2);
$(".elective_subjects").append(option_choose_c,e1);