Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';t使用GAS中的JQuery从脚本调用脚本_Javascript_Jquery_Google Apps Script_Google Apps - Fatal编程技术网

Javascript Can';t使用GAS中的JQuery从脚本调用脚本

Javascript Can';t使用GAS中的JQuery从脚本调用脚本,javascript,jquery,google-apps-script,google-apps,Javascript,Jquery,Google Apps Script,Google Apps,我在执行脚本时遇到了一些困难。我不熟悉HTML和JQuery 使用Google工作表和Google应用程序脚本: 我有3个问题文件: 'sidebar.html' 'popup.html' 'scriptsJS.html' “侧边栏”和“弹出窗口”的脚本都在“scriptsJS”中 按钮“#btnRefreshData”绑定到“侧边栏”中的一个按钮;此按钮和相关脚本按预期工作 我试图从另一个绑定到“popup.html”中不同buttin的脚本触发同一按钮,但调用被忽略 下面的脚本位于“scr

我在执行脚本时遇到了一些困难。我不熟悉HTML和JQuery

使用Google工作表和Google应用程序脚本:

我有3个问题文件:

'sidebar.html'
'popup.html'
'scriptsJS.html'
“侧边栏”和“弹出窗口”的脚本都在“scriptsJS”中

按钮“#btnRefreshData”绑定到“侧边栏”中的一个按钮;此按钮和相关脚本按预期工作

我试图从另一个绑定到“popup.html”中不同buttin的脚本触发同一按钮,但调用被忽略

下面的脚本位于“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”).trigger(“click”)/我猜这是一个事件委派问题,您如何绑定
#btnRefreshData
的click处理程序?如果您不委派它,请尝试按如下方式委派它:

 $( "#btnRefreshData" ).on( "click", function() {} ); //My guess on how you are binding it.

 $( document ).on( "click", "#btnRefreshData", function() {} ); //Delegating the event.

应用程序脚本使用caja编译代码。对于设计,您可以在普通javascript上获得的一些选项被禁用,其中之一就是通过编程触发单击。这就是您提到的代码被忽略的原因。 在这种情况下,最好调用在点此方法内的按钮“#btnRefreshData”时执行的方法

在这里你可以找到一些关于这个的解释:

谢谢你,taxicala…不幸的是,我无法让它工作。加载时,$(文档).ready(函数(){$(“#btnRefreshData”)。触发器(“单击”)});在我将此按钮更改为“委派”样式绑定后,未能触发此按钮的单击事件。不过,感谢您的反馈…我很感激。感谢Gerardo。这听起来很完美,所以我将所有方法都移动到了doThis中,但运气不佳。调用的方法从sidebar.html中的元素读取值。当sidebar.html调用doThis时,工作正常,但当popup.html调用时,方法失败。我能够截获一个失败处理程序,该处理程序返回“NetworkError:Connection failure due to HTTP 0”。我认为popup.html不能利用sidebar.html页面上的元素绑定?