Combine change and onload events

前端 未结 4 631
长发绾君心
长发绾君心 2021-01-26 23:24

I have coded this where I add / delete classes when you select from the form. However if i choose as default select the 2nd select e.g.

4条回答
  •  春和景丽
    2021-01-27 00:17

    You can use triggerHandler() for an initial trigger, just append it to your chain:

    $('#destination').change(function() {
       var dest = $('#destination').find(":selected").text();
    
       if (dest === 'destination1') {
           console.log('here1');
           $('#destin').removeClass("has-warning");
           $('#destin').addClass("has-success");
    
       } else if (dest === 'destination2') {
           console.log('here2');
           $('#destin').removeClass("has-success");
           $('#destin').addClass("has-warning");
       }
     }).triggerHandler("change");
    

提交回复
热议问题