单击 GoogleDoc 侧边栏上的按钮时,我需要执行 function()
I need to execute a function() when clicking a button on GoogleDoc sidebar
我已经在我的 Google 文档上创建了一个非常简单的边栏作为附加组件。但是,由于我在这件事上没有我想要的那么先进,所以我被困住了。这个侧边栏只有一个文本框和一个按钮,用户可以在其中输入字符串文本,然后只需单击按钮即可 'execute a function'(这就是我需要帮助的地方)。
我有这个功能,而且很管用!但是,我不知道如何构建脚本来执行侧边栏按钮的功能。
我对这个问题做了一些研究,我发现什么也没做,也没有给出任何错误信息。它只是行不通。如果你们知道我在哪里可以找到实现我目标的前一个问题,请告诉我!如果没有,请告诉我怎么做。
这是 html 文件代码:
<!DOCTYPE html>
<!-- Use this CSS stylesheet to ensure that add-ons styling
matches the default Google Docs styles -->
<link href="https://ssl.gstatic.com/docs/script/css/add-ons.css"
rel="stylesheet">
<!-- The sidebar will have a input box and the search button -->
<div class="sidebar">
<!-- The search box -->
<div class="block form-group">
<input type="text" id="url_text" placeholder="Enter DB spreadsheet url" />
<button class="blue" id="search_phrases">Search Phrases</button>
</div>
<!-- Load the jQuery library from the Google CDN -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<script>
// Attach click handlers after the Sidebar has loaded in Google Docs
$(function() {
// Here is my problem----------------------------------------
$('#search_phrases').click(function() {
higlightPhrases($('#url_text').val())
});
// If the user presses the Enter key in the search box, perform a search
$('#url_text').keyup(function(e) {
if (e.keyCode === 13) {
$('#search_phrases').click();
}
});
});
</script>
而且,我的函数如下(在脚本文件中):
function higlightPhrases(db_url) {
// For comfortable reasons, I've reduced the function script into a message.
DocumentApp.getUi().alert(db_url);
}
感谢您的帮助!
阿杰
只是为了关闭post一个答案,正如@TheMaster上面评论的那样,我被推荐看到
the relevant section of the official apps script documentation: "Client server communication"? See info page for more details.
所以,我已经修复了我的代码:
// Here is(was) my problem----------------------------------------
$('#search_phrases').click(function() {
google.script.run.higlightPhrases($('#url_text').val())
});
谢谢! @TheMaster
我已经在我的 Google 文档上创建了一个非常简单的边栏作为附加组件。但是,由于我在这件事上没有我想要的那么先进,所以我被困住了。这个侧边栏只有一个文本框和一个按钮,用户可以在其中输入字符串文本,然后只需单击按钮即可 'execute a function'(这就是我需要帮助的地方)。
我有这个功能,而且很管用!但是,我不知道如何构建脚本来执行侧边栏按钮的功能。
我对这个问题做了一些研究,我发现什么也没做,也没有给出任何错误信息。它只是行不通。如果你们知道我在哪里可以找到实现我目标的前一个问题,请告诉我!如果没有,请告诉我怎么做。
这是 html 文件代码:
<!DOCTYPE html>
<!-- Use this CSS stylesheet to ensure that add-ons styling
matches the default Google Docs styles -->
<link href="https://ssl.gstatic.com/docs/script/css/add-ons.css"
rel="stylesheet">
<!-- The sidebar will have a input box and the search button -->
<div class="sidebar">
<!-- The search box -->
<div class="block form-group">
<input type="text" id="url_text" placeholder="Enter DB spreadsheet url" />
<button class="blue" id="search_phrases">Search Phrases</button>
</div>
<!-- Load the jQuery library from the Google CDN -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<script>
// Attach click handlers after the Sidebar has loaded in Google Docs
$(function() {
// Here is my problem----------------------------------------
$('#search_phrases').click(function() {
higlightPhrases($('#url_text').val())
});
// If the user presses the Enter key in the search box, perform a search
$('#url_text').keyup(function(e) {
if (e.keyCode === 13) {
$('#search_phrases').click();
}
});
});
</script>
而且,我的函数如下(在脚本文件中):
function higlightPhrases(db_url) {
// For comfortable reasons, I've reduced the function script into a message.
DocumentApp.getUi().alert(db_url);
}
感谢您的帮助! 阿杰
只是为了关闭post一个答案,正如@TheMaster上面评论的那样,我被推荐看到
the relevant section of the official apps script documentation: "Client server communication"? See info page for more details.
所以,我已经修复了我的代码:
// Here is(was) my problem----------------------------------------
$('#search_phrases').click(function() {
google.script.run.higlightPhrases($('#url_text').val())
});
谢谢! @TheMaster