![](/img/trans.png)
[英]Call javascript function from html file in google apps script
[英]Javascript : how to call a function from an html page that is in a script file
我有两个文件,一个名为index.html
,另一个名为index.js
我将Node.js与Electron结合使用来制造一个不和谐的机器人。 由于电子原因,我的界面是html格式,因此我有一些文本框可以更新我的机器人的状态。 我使用Discord.js
这是导致出现问题index.html
的代码:
<div id="ActivityChanger">
<select id="ActivityTypeList">
<option value="none">None</option>
<option value="PLAYING">Playing</option>
<option value="WATCHING">Watching</option>
<option value="LISTENING">Listening To</option>
<option value="STREAMING">Streaming</option>
</select>
<input type="text" name="TEST" size="40" id="ActivityGame" />
<button name="Update" type="submit" value="update-true" id="UpdateButton" onclick="UpdateActivity()">
Update
</button>
<script scr="index.js"></script>
</div>
按下“ Update
按钮时,此代码通常会发送文本框和下拉列表的信息,但我不想在.html文件中包含Javascript,因此可以使用
function UpdateActivity(){
var selectedValue = document.getElementById("ActivityTypeList").value;
var selectedGame = document.getElementById("ActivityGame").value;
if((selectedValue !== 'none') && (selectedGame !== null)){
UserBot.user.setActivity(selectedGame, {type: selectedValue,})
console.log('Updated Status' + ` to ${selectedValue} ${selectedGame} `)
}
}
UserBot是我的客户
但是当我在控制台中按下burron时,它说未定义UpdateActivity()
如果这是您包含的真实HTML,则其中包含一个错字:
<script scr="index.js"></script>
那应该是src
,而不是scr
:
<script src="index.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.