esolve
V2EX  ›  问与答

如何判断下拉选项第一项选中与否?

  •  
  •   esolve · Oct 30, 2017 · 1521 views
    This topic created in 3204 days ago, the information mentioned may be changed or developed.

    无论下拉选项如何选

    if ($(select.id + ' option:first').is(':selected'))
    

    总是 false

    if ($('select:option:first').is(':selected'))
    

    又总是 true

    2 replies    2017-10-30 14:52:12 +08:00
    SourceMan
        1
    SourceMan  
       Oct 30, 2017
    果然是你,刚刚我回到那个怎么判断是否是 select 还是 CheckBox 的
    你这样不行呐,先去搜索下,然后再自己实践下,再简单的问题折腾 1、2 个钟也是很正常的,然后才有收获呀。
    一来就发帖,即时马上解决了印象也不深
    SourceMan
        2
    SourceMan  
       Oct 30, 2017
    你这个思路错了,你要判断 select 选中的 value 是否和你要判断 option 的 value 相同就可以了呀。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2678 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 12:26 · PVG 20:26 · LAX 05:26 · JFK 08:26
    ♥ Do have faith in what you're doing.