单击GoogleDoc侧边栏上的按钮时,我需要执行一个function() [英] I need to execute a function() when clicking a button on GoogleDoc sidebar

查看:53
本文介绍了单击GoogleDoc侧边栏上的按钮时,我需要执行一个function()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在自己的Google文档上创建了一个非常简单的边栏作为加载项.但是,由于我在这件事上没有自己想要的先进,所以我被困住了.此侧边栏只有一个文本框和一个按钮,用户可以在其中输入字符串文本,然后只需单击该按钮即可执行功能"(这是我需要帮助的地方).

I have already created a very simple sidebar on my Google Doc as an Add-on. But, since I am not so advanced as I wanted in this matter, I'm stuck. This sidebar has simply a textbox and a button where the user would enter a string text, then simply click the button to 'execute a function' (and here is where I need help).

我具有该功能,并且可以正常工作!但是,我不知道如何通过侧边栏的按钮来构建脚本来执行功能.

I have the function and it worked! But, I don't know how to build the script to execute the function by the sidebar's button.

我对此事进行了研究,发现没有做任何事情,也没有给出任何错误消息.只是行不通.如果你们知道我在哪里可以找到可以实现我的目标的以前的问题,请告诉我!如果没有,请告诉我该怎么做.

I've made some research in this matter, and what I found didn't do anything nor gave any error messages. It just won't work. If you guys know where can I find here a former question that achieves my goal, please let me know! If not, please tell me how to do it.

这是html文件代码:

Here's the html file code:

<!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>

而且,我的功能如下(在脚本文件中):

And, my function is the following (within a script file):

 function higlightPhrases(db_url) {
     // For comfortable reasons, I've reduced the function script into a message.
     DocumentApp.getUi().alert(db_url);
 }

感谢您的帮助!AJ

推荐答案

只需关闭答案即可,正如@TheMaster在上面评论的那样,建议我看看

Just to close the post with an answer, as @TheMaster commented above, I was recommended to see

官方应用程序脚本文档的相关部分:客户端服务器通信"?有关更多详细信息,请参见信息页面.

因此,我已经像这样修复了我的代码:

And so, I've fixed my code like this:

// Here is(was) my problem----------------------------------------
$('#search_phrases').click(function() {
google.script.run.higlightPhrases($('#url_text').val())
});

谢谢!@TheMaster

Thank you! @TheMaster

这篇关于单击GoogleDoc侧边栏上的按钮时,我需要执行一个function()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆