【发布时间】:2020-11-23 17:32:31
【问题描述】:
我有一个 code.gs,它创建一个菜单,用 html 打开一个侧边栏。 我的html是这样的:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
</head>
<body>
<button onclick='ativarFeedbacks()'>Feedback</button>
<div id="aviso">aaasaaa</div>
<script>
function callback(resposta) {
document.getElementById("aviso").innerHTML=resposta;
}
function ativarFeedbacks() {
google.script.run.withSuccessHandler(callback).escrever();
}
</script>
</body>
</html>
我的code.gs是这样的:
function onOpen(e) {
FormApp.getUi()
.createAddonMenu()
.addItem('Configurar feedbacks', 'showSidebar')
.addToUi();
}
function showSidebar() {
var ui = HtmlService.createHtmlOutputFromFile('teste2')
.setTitle('Feedback');
FormApp.getUi().showSidebar(ui);
}
function escrever(){
return "<h1> salve salve </h1>"
}
但是,当我运行 onOpen 时,我打开侧边栏并按下按钮,没有任何反应。我在 id "aviso" 上的 innerHTML 没有改变,就像 escrever() 没有返回任何内容一样。我不理解这种行为。我该怎么办?
【问题讨论】:
-
如果你要使用 type="button" 那么你应该使用输入标签而不是按钮。您应该能够通过控制台和开发工具进行调试的任何方式。如果您不知道怎么做,那么这是学习的好时机。
-
换一种说法,按钮元素doesn't have a type attribute。
标签: javascript html google-apps-script google-forms