如何在select中的最后一个位置呈现选项?

时间:2015-08-21 16:54:17

标签: javascript jquery

我有一个下拉菜单

enter image description here

<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>

__ 做这样的事情的最有效方法是什么?

0 个答案:

没有答案