bootstrap select option display value instead of text

前端 未结 2 1695
说谎
说谎 2021-01-24 02:53

this might have been answered already, but I don\'t think this particular question has been answered.

I have a dropbox (select & option) and I want to display the va

相关标签:
2条回答
  • 2021-01-24 03:20

    With Jquery code, try this one:

    $('#inputmsgType').click(function() {
                $('#description').html("Option value is:" + $('#inputmsgType').val() +
                        "<br>Option Description is: " + $('#inputmsgType option:selected').text());
            });
    
    0 讨论(0)
  • 2021-01-24 03:35

    Something like this ?

    Bootply : http://www.bootply.com/128894

    JS :

    $('#inputmsgType').on('change mouseleave', function(){
      $('#inputmsgType option').each(function(){
        $(this).html( $(this).attr('desc') ); 
      });
      $('#inputmsgType option:selected').html(  $('#inputmsgType option:selected').attr('value')   );
    
    });
    
    $('#inputmsgType').on('mouseover', function(){
      $('#inputmsgType option').each(function(){
        $(this).html( $(this).attr('desc') ); 
      });
    });
    

    HTML :

    <select id="inputmsgType" class="form-control width-90">
    <option value="0" desc="description0">description0</option>
    <option value="1" desc="description1">description1</option>
    <option value="2" desc="description2">description2</option>
    </select>
    
    0 讨论(0)
提交回复
热议问题