使用 Html 服务的 JQuery 示例

标签 jquery jquery-ui google-apps-script

我正在尝试弄清楚 HTML 服务中的 JQuery,但我似乎无法让它工作。

按照 https://developers.google.com/apps-script/html_service 处的第一个示例我可以得到 Hello World !显示。

但是如果我添加脚本标签并指向 JQuery,它就不起作用,页面上什么也没有显示,它只是空白!

这是我的 code.gs 文件:

function doGet() {
  return HtmlService.createHtmlOutputFromFile('myPage');
}

工作的 myPage.html 看起来像这样:

<html>
  <body>
    Hello World!
  </body>
</html>

的看起来像这样:

<html>
  <body>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"/>
    Hello World!
  </body>
</html>

那么如何让 JQuery(最终是 JQueryUI)工作呢?有没有任何示例或教程?

谢谢

最佳答案

这是一个工作的 Accordion html 文件,因此只需将其命名为 myPage.html

我发现某些版本的 jquery 无法与 GAS 一起使用,即使它们位于兼容性列表中。

<html>
<head>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/humanity/jquery-ui.css" type="text/css" />
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
  <script>
  $(document).ready(function() {
    $("#accordion").accordion({ collapsible: true, active: false });
    $('.header-checkbox').click(
    function(e){
        e.stopPropagation();
    }
    );
  });
  </script>
</head>
<body style="font-size:62.5%;">

<div id="accordion">
        <h3 id='example'>
            <a href='#'>
                <label><input class='header-checkbox' type='checkbox' />Title</label>
            </a>
        </h3>
        <div>
        <p>
        Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
        ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
        amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
        odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
        </p>
        </div>
        <h3 id='example'>
            <a href='#'>
                <label><input class='header-checkbox' type='checkbox' />Title2</label>
            </a>
        </h3>
        <div>
        <p>
        Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
        ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
        amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
        odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
        </p>
        </div>
        <h3 id='example'>
            <a href='#'>
                <label><input class='header-checkbox' type='checkbox' />Title3</label>
            </a>
        </h3>
        <div>
        <p>
        Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
        ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
        amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
        odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
        </p>
        </div>
    </div>
</div>

</body>
</html>

关于使用 Html 服务的 JQuery 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12466681/

相关文章:

jQuery UI 复选框按钮全选问题

javascript - 将 showModalDialog() 的内容添加到剪贴板 Google 脚本

google-apps-script - 有没有办法通过脚本在Google开发者控制台中启用高级Google服务?

javascript - Flot 从一点到另一点设置一条垂直线的动画

javascript - jQuery:addClass() 和 removeClass() 出于某种原因不起作用

jquery - 捕获表单中的所有 HTML,包括没有帖子的文本字段值

javascript - JS OpenSeadragon : when click on the component -> add a marker

javascript - jQuery 小部件没有方法 "extend"

jquery - 第二次聚焦时不会触发自动完成功能

javascript - 调用脚本用户日历-GAS