电子多按钮Javascript问题
我把我的网页放在Electron中,一切都很顺利,除了页面上的一些按钮,只有第一个按钮正确地执行从javascript数组中随机选取内容的功能,而其余按钮不工作,但在浏览器中一切正常。是否需要在电子多按钮Javascript问题,javascript,html,node.js,electron,Javascript,Html,Node.js,Electron,我把我的网页放在Electron中,一切都很顺利,除了页面上的一些按钮,只有第一个按钮正确地执行从javascript数组中随机选取内容的功能,而其余按钮不工作,但在浏览器中一切正常。是否需要在index.js中包含其他函数以允许运行多个javascript函数 代码如下: 这是HTML端(在浏览器中工作): <!doctype html> <html> <head> <title>What Should I Draw</title&
index.js
中包含其他函数以允许运行多个javascript函数
代码如下:
这是HTML端(在浏览器中工作):
<!doctype html>
<html>
<head>
<title>What Should I Draw</title>
<style>
.button {
background-color: #008CBA;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
top: 50%;
}
.wrapper {
text-align: center;
}
.demo {
text-align: center;
color: #008CBA;
text-transform: uppercase;
font-size: 300%;
}
.remo {
text-align: center;
color: #008CBA;
text-transform: uppercase;
font-size: 300%;
}
.temo {
text-align: center;
color: #4CAF50;
text-transform: uppercase;
font-size: 200%;
}
.zemo {
text-align: center;
color: #4CAF50;
text-transform: uppercase;
font-size: 200%;
}
.kemo {
text-align: center;
color: #4CAF50;
text-transform: uppercase;
font-size: 200%;
}
.uemo {
text-align: center;
color: #4CAF50;
text-transform: uppercase;
font-size: 200%;
}
.buttons {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
top: 50%;
}
</style>
</head>
<body>
<div class="wrapper">
<input id="btnSearch" class="button" type="button" value="Randomize Subject" onclick="getRandomArrayElements(3);"/>
<input id="btnSearch" class="button" type="button" value="Randomize Restriction" onclick="GetValue();"/>
</div>
<p id="demo" class="demo"></p>
<p id="remo" class="remo"></p>
<script>
function getRandomArrayElements (count) {
var arr = ['Swamp', 'Tank', 'Claws', 'Flying Tank'];
var shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index;
while (i-- > min) {
index = Math.floor((i + 1) * Math.random());
temp = shuffled[index];
shuffled[index] = shuffled[i];
shuffled[i] = temp;
}
document.getElementById("demo").innerHTML = shuffled.slice(min);
}
</script>
<div>
<script>
function GetValue () {
var myArray = new Array("Steampunk", "Horror", "Cartoon", "Anime", "Cheesy");
var random = myArray[Math.floor(Math.random() * myArray.length)];
document.getElementById("remo").innerHTML = random;
}
</script>
<div class="wrapper">
<input id="btnSearch" class="buttons" type="button" value="Randomize Type of Landscape" onclick="Landscape();"/>
<input id="btnSearch" class="buttons" type="button" value="Randomize Man Made Element" onclick="Manmade();"/>
<input id="btnSearch" class="buttons" type="button" value="Randomize Time of Day" onclick="Timeofday();"/>
<input id="btnSearch" class="buttons" type="button" value="Randomize Weather" onclick="Weather();"/>
<p id="kemo" class="kemo"></p>
<p id="uemo" class="uemo"></p>
<p id="zemo" class="zemo"></p>
<p id="temo" class="temo"></p>
</div>
<script>
function Weather () {
var myArray = new Array("Clear Skies", "Clear Skies", "Clear Skies", "Clear Skies", "Clear Skies", "Partly Cloudy");
var random = myArray[Math.floor(Math.random() * myArray.length)];
document.getElementById("temo").innerHTML = random;
}
</script>
<div>
<script>
function Timeofday () {
var myArray = new Array("Noon", "Morning", "Sunrise", "Afternoon", "Magic Hour", "Sundown", "Night", "Twilight", "Aurora", "Late Night", "Noon", "Noon", "Noon", "Noon", "Noon", "Noon", "Noon");
var random = myArray[Math.floor(Math.random() * myArray.length)];
document.getElementById("zemo").innerHTML = random;
}
</script>
<div>
<script>
function Landscape () {
var myArray = new Array("Canyon", "Grand Canyon", "Beach", "Cliff", "Mountain Range");
var random = myArray[Math.floor(Math.random() * myArray.length)];
document.getElementById("kemo").innerHTML = random;
}
</script>
<div>
<script>
function Manmade () {
var myArray = new Array("Cityscape", "Futuristic Cityscape", "Futuristic City", "Futuristic Cityscape");
var random = myArray[Math.floor(Math.random() * myArray.length)];
document.getElementById("uemo").innerHTML = random;
}
</script>
</div>
</div>
</div>
</div>
</body>
</html>
Package.js
const electron = require('electron')
const {app, BrowserWindow} = electron
app.on('ready', function() {
var mainWindow = new BrowserWindow({
width: 1200,
height: 800,
})
mainWindow.loadURL('file://' + __dirname + '/Test.html')
})
{
"name": "Drawing",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start":"electron ."
},
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"electron-prebuilt": "^1.4.13"
}
}
id
在整个文档中应该是唯一的。您对所有输入都使用相同的id
s。请详细说明,您是在谈论我的段落id还是其他什么。我尝试了您的建议,并将它们全部切换到类,但这会把一切都搞砸,我不知道需要在getElementbyID中输入什么。欢迎使用stackoverflow,除了按照正确的建议将ID更改为唯一之外,我建议开始接受您问题的答案,我已经回顾了您之前问题的答案,其中两个回答了您的问题。最佳实践是接受他们,奖励社区,并确保社区在未来回答您的问题。另外,关于这个具体问题,什么叫"乱七八糟"??我认为你最好用你的代码创建一个,这样我们就可以很容易地进行调查。祝你好运。你是想写package.json
而不是package.js
?id
在整个文档中应该是唯一的。您对所有输入都使用相同的id
s。请详细说明,您是在谈论我的段落id还是其他什么。我尝试了您的建议,并将它们全部切换到类,但这会把一切都搞砸,我不知道需要在getElementbyID中输入什么。欢迎使用stackoverflow,除了按照正确的建议将ID更改为唯一之外,我建议开始接受您问题的答案,我已经回顾了您之前问题的答案,其中两个回答了您的问题。最佳实践是接受他们,奖励社区,并确保社区在未来回答您的问题。另外,关于这个具体问题,什么叫"乱七八糟"??我认为你最好用你的代码创建一个,这样我们就可以很容易地进行调查。祝你好运。你是想写package.json
而不是package.js
?