set dropdown selected value with backbone

后端 未结 1 1496
轮回少年
轮回少年 2021-01-05 18:53

I want to set my dropdown menu from my js. Basically, i want to be able to set the updated drop down value from the js.

my.html

  
1条回答
  •  感情败类
    2021-01-05 19:10

    You should start your function names with a lowercase letter (as per Mr Crockford) and use more descriptive function names.

    In order to set the value of a select list, use option[value='x'] syntax. Assuming you'd like to set the second option:

    events : {
      'change #ddpFilter' : 'filterDdpSelect'
    },
    
    filterDdpSelect: function(e){
      var selectValue = 2;
      $("#ddpFilter option[value='" + selectValue + "']").attr("selected", "selected");
    }
    

    0 讨论(0)
提交回复
热议问题