代码之家  ›  专栏  ›  技术社区  ›  Ben Shelock

点击菜单后,选择菜单关闭

  •  0
  • Ben Shelock  · 技术社区  · 16 年前

    我创建了一个 <select> 使用javascript的菜单,然后将其附加到页面。但当我点击它时,它会立即关闭。

    这是我的密码,我被难住了。

    var accounts = [
        ['user1', 'password'],
        ['user2', 'passowrd']
    ]
    
    function html(){
        var button = '<a href="#" id="switchacc">Switch User</a>&nbsp;• &nbsp;';
        $('a[href=search.php]')[0].before(button);
    
        $('#switchacc').click(function(){
            $(this).html('<select id="accounts">'+ accountss +'</select>');
            return false;
        });
    
    
        var accountss = '';
        for(i = 0; i <= accounts.length; i++){
            accountss = accountss + '<option name="' + accounts[i][0] + '" value="' + i + '">' + accounts[i][0] + '</option>';
        }   
    }
    html();
    
    1 回复  |  直到 16 年前
        1
  •  1
  •   janmoesen    16 年前

    你为什么要嵌入你的 select 在那 a 链接?见 this fiddle 例如。不能在链接中嵌入列表。

    推荐文章