Google chrome dropdown list options ordering seems to be incorrect

前端 未结 2 604
一整个雨季
一整个雨季 2021-01-15 16:31

I am using the following code for rendering a select box in one of my form and when i inspects i can see the following code in Firefox


                        
    
提交评论

  • 2021-01-15 16:54

    It's not a real good practice but...

    If you add a space to the value chrome will not consider value a number and won't sort them by value.

    Example:

    <select>
      <option value=" 3">Third</option>
      <option value=" 1">First</option>
      <option value=" 2">Second</option>
    </select>
    

    The good side is that you have not to add and then remove alphabetic characters from ID like someone suggested (don't remember if in this or other post with similar question), you could easily trim it but most of the times the space is just ignored and if you post or get those to another file they will simply see the integer value not the space.

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