Can an Option in a Select tag carry multiple values?

前端 未结 15 2271
执念已碎
执念已碎 2020-11-22 17:42

I got a select tag with some options in a HTML form:
(the data will be collected and processed using PHP)

Testing:


                        
    
提交评论

  • 2020-11-22 18:09

    you can use multiple attribute

    <SELECT NAME="Testing" multiple>  
     <OPTION VALUE="1"> One  
     <OPTION VALUE="2"> Two  
     <OPTION VALUE="3"> Three
    

    0 讨论(0)
  • 2020-11-22 18:10

    What about html data attributes? That's the easiest way. Reference from w3school

    In your case

    $('select').on('change', function() {
      alert('value a is:' + $("select option:selected").data('valuea') +
        '\nvalue b is:' + $("select option:selected").data('valueb')
      )
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
    <select name="Testing">
      <option value="1" data-valuea="2010" data-valueb="2011"> One
        <option value="2" data-valuea="2122" data-valueb="2123"> Two
          <option value="3" data-valuea="0" data-valueb="1"> Three
    </select>

    0 讨论(0)
  • 提交回复
    热议问题