当我运行它时,我得到错误getInfo未定义。那么我该如何实现呢?
(我知道这不是一个安全的登录,我现在不担心这个)
document.getElementById("submit").addEventListener("click", function getInfo(){
var user = document.getElementById('username');
var username = user.value;
var pass = document.getElementById('password');
var password = pass.value;
return [username, password];
});
var userinfo = getInfo();
var username = userinfo[0];
var password = userinfo[1];
console.log(username, password);
答案 0 :(得分:2)
这个怎么样:
function getInfo(){
var user = document.getElementById('username');
var username = user.value;
var pass = document.getElementById('password');
var password = pass.value;
return [username, password];
});
document.getElementById("submit").addEventListener("click", function (){ getInfo();});
//or
//document.getElementById("submit").addEventListener("click", getInfo);
var userinfo = getInfo();
var username = userinfo[0];
var password = userinfo[1];
console.log(username, password);