HTML select shows value instead of text

后端 未结 5 923
花落未央
花落未央 2021-01-11 16:53

Is it possible in a html select, to display the value of the option instead of the text?

It\'s gonna be used for displaying a long disription in the dro

5条回答
  •  礼貌的吻别
    2021-01-11 16:57

    I found a solution that might solve your problem:

    HTML:

    
    

    jQuery:

    $('#countryCode option:selected').html($('#countryCode option:selected').attr('value')); // already changed onload
    
    $('#countryCode').on('change mouseleave', function(){
        $('#countryCode option').each(function(){
          $(this).html( $(this).attr('data-text') ); 
        });
        $('#countryCode option:selected').html(  $('#countryCode option:selected').attr('value')   );
        $(this).blur();
    });
    $('#countryCode').on('focus', function(){
        $('#countryCode option').each(function(){
            $(this).html( $(this).attr('data-text') ); 
        });
    });
    

    http://jsfiddle.net/9y43gh4x/

提交回复
热议问题