javascript - 使用输入创建代码?Javascipt 图形用户界面
问题描述
我正在编写一个电子网络应用程序,需要该应用程序根据使用输入做一些事情:
基本上,在用户输入时,我的代码会保存var string = "stuff"
在它保存的另一个输入上,var string = "other_stuff
是否有可能
#1 - 检测用户输入了多少次来获取一个变量并使用诸如此类的东西var string_1 = "stuff"
保存var string_2 = "other_stuff"
它
#2 - 当这些按钮被按下时,在一个循环中创建代码(将在按钮按下时运行),看起来像这样
try{
function('string_1');
}
catch (error)
console.log(error);
try{
function('string_2');
}
catch (error)
console.log(error);
解决方案
在按钮按下array.push(str);
时,用于添加到数组的末尾。
然后使用
function txt_download(str) {
// code stuff
}
for (const element of array) {
txt_download(element)
}
运行函数