【发布时间】:2015-07-06 22:21:48
【问题描述】:
我在执行脚本时遇到了一些困难。我是 HTML 和 JQuery 的新手。
使用 Google 表格和 Google Apps 脚本:
我有 3 个文件有问题:
'sidebar.html'
'popup.html'
'scriptsJS.html'
'sidebar' 和 'popup' 的脚本都在 'scriptsJS' 中。
按钮“#btnRefreshData”绑定到'sidebar'中的按钮;此按钮和相关脚本按预期工作。
我正在尝试从绑定到“popup.html”中不同按钮的另一个脚本触发相同的按钮,但调用被忽略。
下面的脚本在'scriptsJS.html'中,并绑定到'popup.html'中的一个按钮:
$( '#btnOpenSelectedItem' ).click(function() {
this.disabled = true;
var item = $( "#resultsList" ).find(':selected').val();
google.script.run
.withSuccessHandler(
function(msg, element) {
element.disabled = false;
doThis();
google.script.host.close();
})
.withFailureHandler(
function(msg, element) {
showStatus(msg, 'error');
element.disabled = false;
})
.withUserObject(this)
.openSelectedItem(item);
});
上面的脚本执行正确;我的数据加载,然后它调用'doThis':
function doThis () {
alert ('do this called');
$( "#btnRefreshData" ).trigger( "click" ); //<-- ignored
};
上面的脚本成功显示警报(用于测试),然后尝试触发#btnRefreshData。 #btnRefreshData 绑定到“sidebar.html”,并导致侧边栏中的数据重新填充。
同样,所有这些脚本都在同一个文件中,但是当我从“popup.html”调用#btnRefreshData(绑定到“sidebar.html”)时,它被忽略了。
我希望找到一种方法来触发此事件。谢谢你能给我的任何帮助。
【问题讨论】:
标签: javascript jquery google-apps-script google-apps