【发布时间】:2016-01-08 20:51:41
【问题描述】:
我们有一个用于 Doc 的插件,它将数据插入到文档中,我们还希望它在您单击 再次 按钮时删除文本,就像一个开关一样。就像现在一样,在第二次、第三次按下按钮时,依此类推......它会在已经存在的文本上填充新文本。
客户端:
<div class="block" id="button-bar">
<button onclick="google.script.run.insertTextA();" id="TextA">Text A</button>
<button onclick="google.script.run.insertTextB();" id="TextB">Text B</button>
</div>
服务器端:
function insertTextA() {
var body = DocumentApp.getActiveDocument().getBody();
var text = body.editAsText();
text.insertText(11, 'There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..');
}
function insertTextB() {
var body = DocumentApp.getActiveDocument().getBody();
var text = body.editAsText();
text.insertText(12, 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old..');
}
【问题讨论】:
-
您尝试删除它的目的是什么?
标签: javascript html google-apps-script google-api