我想在我的代码中修改一些内容并且不知道如何使这个工作...我的代码有点大,所以我将用例子来解释我想要的东西:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="stylesheets/application.css">
</head>
<body>
<label>Enter value : </label><input type="text" maxlength="512" id="reg_expr"/>
<div id="button">OK</div>
<div id="nfa"></div>
<script src="script1.js"></script>
<script src="script2.js"></script>
<script src="script3.js"></script>
</body>
</html>
所以这是我的HTML代码,所以我要做的是在用户在文本输入中输入值并单击OK之前不执行这3个脚本。该值将在js文件中使用,因此我必须在单击“确定”后获取该值。
有人可以解释这是如何起作用的吗?
编辑:问题在于jQuery没有在Electron上执行,解决方案:http://ourcodeworld.com/articles/read/202/how-to-include-and-use-jquery-in-electron-framework
答案 0 :(得分:2)
我建议您在单击按钮后动态加载脚本。这可以通过jQuery完成:https://api.jquery.com/jquery.getscript/
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="stylesheets/application.css">
<title>NFA2DFA</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<label>Enter value : </label><input type="text" maxlength="512" id="reg_expr"/>
<div id="button" onclick="loadScripts();">OK</div>
<div id="nfa"></div>
<script>
function loadScripts() {
// Is the input empty?
var value = $("#reg_expr").val();
if (value.length != 0) {
// Loads and executes the scripts
console.log(value); // Displays the value of the input field
$.getScript("script1.js");
$.getScript("script2.js");
$.getScript("script3.js");
}
}
</script>
</body>
</html>
答案 1 :(得分:1)
对于初学者,我建议改变; <div id="button">OK</div>
至<button id="button">OK</button>
。
然后我建议将每个脚本放入函数中,然后你可以使用button属性中的'onClick'事件,如下所示;
<button id="button" onClick="s1Func();s2Func();s3Func();">OK</button>
更好的方法是让一个函数调用'init'或者适当的东西然后调用3个脚本/函数并让你的按钮onClick甚至调用那个初始化函数。
JSFiddle示例: https://jsfiddle.net/JokerDan/h7htk9Lp/
答案 2 :(得分:0)
您可以使用按钮标记而不是输入标记。我建议你使用像这样的onClick事件:
const value_type
当用户点击按钮时,你的函数()被调用。
结果如下:
<button type="button" onclick="yourFunction()">Click me</button>