我有一个下拉菜单
<select id="assignment-type-dd">
<option value="all">Assignment Type: All</option>
<option value="section exercises">section exercises</option>
<option value="course benchmark">course benchmark</option>
<option value="chapter quiz">chapter quiz</option>
<option value="chapter test">chapter test</option>
</select>
我使用Javascript生成上面的选择。
$.each(responseData, function(i, v) {
var assessmentType = v.assessmentType;
var sameAssignmentType = $('#assignment-type-dd option').filter(function(){
return $(this).text() == assessmentType;
})
if(!sameAssignmentType.length){
//if assessmentType === Course Benchmark append it as last option
$('#assignment-type-dd').append('<option value="' + assessmentType + '">' + assessmentType + '</option>');
}
});
这是我正在尝试使用我的JS生成
<select id="assignment-type-dd">
<option value="all">Assignment Type: All</option>
<option value="section exercises">section exercises</option>
<option value="chapter quiz">chapter quiz</option>
<option value="chapter test">chapter test</option>
<option value="course benchmark">course benchmark</option>
</select>
__ 做这样的事情的最有效方法是什么?