javascript – 浏览器在Google Apps脚本中弹出
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 浏览器在Google Apps脚本中弹出,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3619字,纯文字阅读大概需要6分钟。
内容图文
背景:我已经在Google应用程序脚本的HTML服务中准备了一个表单,我使用Code.gs中的DoGet函数调用该表单.
my doget function
function doGet() {
return HtmlService.createTemplateFromFile('HTMLUI').evaluate();
}
一旦发布,它将呈现一个简单的浏览器表单,其中包含一些标签,输入框,提交,重置和查找按钮.用户将输入信息点击提交,数据将存储在电子表格(背景)中. – 工作正常,直到这里.
现在,当用户点击查找按钮时 – 需要填充弹出窗口类型,在此弹出窗口中,用户可以输入信息(来自下拉列表),所选条目将填入输入框中,可以修改并再次提交.
题:
在浏览器上如何在GAS中使用POP up kind窗口.
我在HTML服务中的查找按钮如下:
<div><input type="button" onclick="createPopup()" value="Find"></div>
最后调用javascript:
<script type="text/javascript">
function createPopup() {
google.script.run.popup(document.forms[0]);
}
</script>
CreatePopup()javascript代码:
function popup(form){
Logger.log("I am first called");
//Mycode should probably go here I think...
Logger.log("I am last called");
}
查看日志时,它显示“我第一次被呼叫”和“我最后被呼叫”.
我的研究:
我发现Spreadsheet.toast(类似的东西)适用于电子表格,但我如何在浏览器上获得小窗口..
解决方法:
jQuery dialog将满足您的需求.它是当前窗口的叠加 – 而不是“弹出”.
demo code here可以轻松适应Google Apps脚本.在这里,删除了大部分额外的位:
Code.js
function doGet() {
var template = HtmlService
.createTemplateFromFile('ModalForm');
var htmlOutput = template.evaluate()
.setSandboxMode(HtmlService.SandboxMode.NATIVE)
.setTitle('jQuery UI Dialog - Modal form');
return htmlOutput;
}
ModalForm.html
<!-- Adapted from http://jqueryui.com/dialog/#modal-form -->
<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
var name = $( "#name" ),
email = $( "#email" ),
password = $( "#password" ),
allFields = $( [] ).add( name ).add( email ).add( password ),
tips = $( ".validateTips" );
function updateTips( t ) {
tips
.text( t )
.addClass( "ui-state-highlight" );
setTimeout(function() {
tips.removeClass( "ui-state-highlight", 1500 );
}, 500 );
}
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Add User": function() {
var bValid = true;
allFields.removeClass( );
// validation removed
if ( bValid ) {
$( "#users tbody" ).append( "<tr>" +
"<td>" + name.val() + "</td>" +
"<td>" + email.val() + "</td>" +
"<td>" + password.val() + "</td>" +
"</tr>" );
$( this ).dialog( "close" );
}
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
allFields.val( "" ).removeClass( );
}
});
$( "#form-action" )
.button()
.click(function() {
$( "#dialog-form" ).dialog( "open" );
});
});
</script>
<!-- body -->
<div id="dialog-form" title="Create new user">
<form>
<fieldset>
<label for="name">Name</label>
<input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" />
<label for="email">Email</label>
<input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
<label for="password">Password</label>
<input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" />
</fieldset>
</form>
</div>
<div id="users-contain" class="ui-widget">
<h1>Existing Users:</h1>
<table id="users" class="ui-widget ui-widget-content">
<thead>
<tr class="ui-widget-header ">
<th>Name</th>
<th>Email</th>
<th>Password</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>john.doe@example.com</td>
<td>johndoe1</td>
</tr>
</tbody>
</table>
</div>
<button id="form-action">Open Modal Form</button>
内容总结
以上是互联网集市为您收集整理的javascript – 浏览器在Google Apps脚本中弹出全部内容,希望文章能够帮你解决javascript – 浏览器在Google Apps脚本中弹出所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。