JQuery set <select> index from the value of attribute

This question already has an answer here:

  • Change the selected value of a drop-down list with jQuery 15 answers

  • Try

    $('#owner_select').val(id);
    

    http://jsfiddle.net/qWycT/


    function select( id ) {
        var select = $( '#owner_select' ),
            option = select.find( 'option' );
    
        option.each( function( index ) {
            if( $( this ).val() == id ) {
                $( this ).attr( 'selected', 'selected' );
            }
        });
    
        select = null, 
        option = null;
    }
    
    链接地址: http://www.djcxy.com/p/83910.html

    上一篇: 我如何使用jQuery更改选择框的选定选项

    下一篇: JQuery从属性的值中设置<select>索引