如何在输入框中创建下拉列表? [英] How to create a drop down list in Input Box?

查看:40
本文介绍了如何在输入框中创建下拉列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了 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:

这是被触发的函数:

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

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