如何在输入框中创建一个下拉列表? [英] How to create a drop down list in Input Box?
问题描述
我创建了 Browser.inputBox
,它仅接受单个文本。但是,我需要创建一个下拉列表,您可以从列表中选择而不是自己输入字符串。
I created Browser.inputBox
which accepts only a single text. However I need to make a drop down list where I can choose from the list instead of typing the string myself.
单击Odoo(在菜单栏中)>设置时创建的inputBox的屏幕截图:
A screenshot of the inputBox I created on clicking Odoo (in menu bar)>Settings:
以下是正在触发的函数:
Here is the function that is being triggered:
function menu_settings(params) {
if (!params){
params = [["url", "URL"], ["dbname", "Database Name"], ["username", "username"], ["password", "password"]];
}
for (var i = 0; i < params.length; i++){
var input = Browser.inputBox("Server Settings", params[i][1], Browser.Buttons.OK_CANCEL);
if (input === "cancel"){
break;
}
else{
ScriptProperties.setProperty(params[i][0], input);
}
}
}
基本上而不是键入文本,我需要一个带有预定义值的下拉列表。
我正在检查浏览器类,我看到没有这样的下拉列表选项。我见过的大多数解决方案都使用单元格中输入的文本中的DataValidation。但是我想在代码中提供下拉列表,而电子表格中没有任何内容。
I was checking the Browser class and I saw there is no such drop down list option. Most solutions that I have seen use DataValidation from texts input in the cells. But I want to give the list for the dropdown in my code and nothing on the spreadsheet.
我该如何实现?
推荐答案
这是打开HTML对话框的代码:
This is the code to open an HTML dialog:
function fncOpenMyDialog() {
//Open a dialog
var htmlDlg = HtmlService.createHtmlOutputFromFile('HTML_myHtml')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(200)
.setHeight(150);
SpreadsheetApp.getUi()
.showModalDialog(htmlDlg, 'A Title Goes Here');
};
您需要一个HTML文件。
You need an HTML file.
<select name="nameYouWant">
<option value="something">Text</option>
<option value="anything">Drop Down Selection</option>
</select>
<hr/>
<ul>
<li>This is a list.</li>
<li>This is line two.</li>
</ul>
<button onmouseup="closeDia()">Close</button>
<script>
window.closeDia = function() {
google.script.host.close();
};
</script>
这篇关于如何在输入框中创建一个下拉列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!