开发者

Select menu closes once you click on it

I create a <select> menu using Javascript then attach it to the page. But when I click on it, it closes immediately.

Here's my code, I'm stumpped.

var accounts = [
    ['user1', 'password'],
    ['user2', 'passowrd']
]

function html(){
    var button = '<a href="#" id="switchacc">Switch User</a>&开发者_如何学Python;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();


Why are you embedding your select in that a link? See this fiddle for an example. You cannot embed a list in a link.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜