jQuery change the select box value based on anchor clicked

后端 未结 3 1218
轮回少年
轮回少年 2021-01-21 16:09

When some one clicks a link I need the select box value to change

Jan
Feb         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-21 16:50

    Why change the value and not select the option that has the "clicked" value?

    Jan
    Feb
    Mar
    
    
    
    

    Script:

    jQuery('a.cli').click(function(event) {
        event.preventDefault();
    
        jQuery('#month option').attr('selected', false);
        jQuery('#month option[value="' + jQuery(this).attr('href') + '"]').attr('selected', true);
    });
    

    Check it out http://jsfiddle.net/jchiotaka/uaLXU/

提交回复
热议问题