简体   繁体   English

从服务器端脚本操作 HTML

[英]Manipulate HTML from server-side scripts

I am trying to manipulate the HTML of an Add-On for Google Docs from server-side Google Apps Script, but have not found a method that supports it.我正在尝试从服务器端 Google Apps 脚本操作 Google Docs 插件的 HTML,但还没有找到支持它的方法。 I would like to add elements when a button is clicked.我想在单击按钮时添加元素。

Is this possible, or can the HTML only be changed by client-side JavaScript or jQuery?这是可能的,还是只能通过客户端 JavaScript 或 jQuery 更改 HTML?

All client-side manipulations and interactions have to be done with client-side JavaScript.所有客户端操作和交互都必须使用客户端 JavaScript 完成。 You can have that code interact with the apps script backend but the actual manipulation needs to be driven within the sandbox.您可以让该代码与应用程序脚本后端交互,但实际操作需要在沙箱内驱动。

The button click could simply send a call to GAS which returns either data or fully formed html (recommend the former) interpreting that and adding it to the page is then handled in a success handler callback.单击按钮可以简单地向 GAS 发送一个调用,该调用返回数据或完整格式的 html(推荐前者)解释它并将其添加到页面然后在成功处理程序回调中处理。 google.run methods google.run 方法

Beware overuse of jQuery, a great deal of what it brings to the party can be done with vanilla js I modern browsers.当心过度使用 jQuery,它给派对带来的很多东西都可以用 vanilla js 和现代浏览器来完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM