Javascript 如何从客户端运行此工作
我已经用尽了我可能尝试的所有可能的排列方式,比如将所有的.js代码移到html中,但是函数不会从文档的侧栏运行,在每次运行中——单击其中任何一个按钮——我必须返回脚本的编辑器来运行侧栏。我在html中嵌入的函数脚本是:Javascript 如何从客户端运行此工作,javascript,google-apps-script,web-applications,Javascript,Google Apps Script,Web Applications,我已经用尽了我可能尝试的所有可能的排列方式,比如将所有的.js代码移到html中,但是函数不会从文档的侧栏运行,在每次运行中——单击其中任何一个按钮——我必须返回脚本的编辑器来运行侧栏。我在html中嵌入的函数脚本是: 函数检查(){ google.script.run.results_run(); } 函数Clear(){ google.script.run.results_clear(); } 检查 清晰的亮点 从onclick=“javascript:Check();”和onclic
函数检查(){
google.script.run.results_run();
}
函数Clear(){
google.script.run.results_clear();
}
检查
清晰的亮点
onclick=“javascript:Check();”
和onclick=“javascript:Clear();”
中删除javascript:
,因为不需要它。最好使用事件侦听器而不是内联JavaScriptgoogle.script.run
时,使用和SuccessHandler
以及和FailureHandler
google.script.run.withFailureHandler(alert.results_run()代码>
function Check() {
google.script.run
.withSuccessHandler(function(){
// if needed do something when the server side function runs succesfully
})
.withFailureHandler(function(error){
// if an error occurss on server side log the error into the console
console.error(error.message,error.stack);
}).results_run();
}
function Clear() {
google.script.run
.withSuccessHandler(function(){
// if needed do something when the server side function runs succesfully
})
.withFailureHandler(function(error){
// if an error occurss on server side log the error into the console
console.error(error.message,error.stack);
}).results_clear();
}