Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击“选择”菜单后,它将关闭_Javascript_Greasemonkey_Html Select - Fatal编程技术网

Javascript 单击“选择”菜单后,它将关闭

Javascript 单击“选择”菜单后,它将关闭,javascript,greasemonkey,html-select,Javascript,Greasemonkey,Html Select,我使用Javascript创建了一个菜单,然后将其附加到页面上。但当我点击它时,它会立即关闭 这是我的密码,我被难住了 var accounts = [ ['user1', 'password'], ['user2', 'passowrd'] ] function html(){ var button = '<a href="#" id="switchacc">Switch User</a>&nbsp;• &nbsp;';

我使用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();
var账户=[
['user1','password'],
['user2','passowrd']
]
函数html(){
var按钮=“•”;
$('a[href=search.php]')[0]。在(按钮)之前;
$('#switchacc')。单击(函数(){
$(this.html(“”+accountss+“”);
返回false;
});
var Accounts='';

对于(i=0;i为什么要将
select
嵌入该
a
链接?请参阅示例。您不能将列表嵌入链接