想象一下这个javascript代码:
"use strict";
var codePc = function (){
var code=[ ];
// code not important
// code not important for the question: print the values to an html list
Return code
var codePlayer = function (list1){
var Intrud = [ ];
// code not important
//code not important for the question: print the values to an html list
Return intrud
var codeCompare = function (list2){
var equal = [ ];
// code not important for the question: it should compare list 1 with list2
// code not important for the question: print the values to an html list
Return equal
function main(){
document.getElementById("button1").addEventListener("click", function(){codePc ();});
document.getElementById("button2").addEventListener("click", function(){codePlayer (code);}); //line 2
document.getElementById("button3").addEventListener("click", function(){codeCompare (intrud);});
};
document.addEventListener("DOMContentLoaded", function(event){ main()});
当我点击button1时,我运行了codePC功能。该函数返回代码。
当我点击button2时,我运行了codePlayer功能。该函数返回intrud。
当我点击button3时,我运行了codeCompare功能。函数返回相等。
当我点击按钮1时,如何使用单击按钮1时产生的var代码来提供功能?
如何将变量代码(入侵和相等)保存为全局变量供以后使用?
当我以这种方式运行3功能时,可以将列表保存在变量中吗?
我无法做到:
Var codeKeep = document.getElementById("button1").addEventListener("click", function(){codePc ();});
韩国社交协会!