18910140161

按钮-在Google站点中添加下拉框-堆栈溢出

顺晟科技

2022-10-18 12:51:17

173

我在谷歌表格里有一些数据。我怎样才能提取数据的基础上,用户的要求,按照一个下拉框,并在谷歌网站生成它。我所面临的挑战。

问题_1-在谷歌网站

中使用下拉框

问题_2-从Google电子表格生成Google站点中的动态数据(或表格)。

分析_1-我已经做了详细的研究,并了解到只有使用第三方插件,我可以做一个选择框。作为一个新手,需要一些基于此的指导方针。没有任何第三方插件是不可能的。

分析_2-或者是否有任何其他选项来生成基于Google站点中的选择的操作。据我所知,脚本是不可能在谷歌网站。那么我该如何做一个按钮点击动作呢?

在这方面

需要一些指导。


顺晟科技:

这是一些用于将选项加载到选择框中的JavaScript代码。

function updateSelect(vA)//array of values that go into the drop down or select box
{
  var select = document.getElementById("sel1");
  select.options.length = 0; 
  for(var i=0;i<vA.length;i++)
  {
    select.options[i] = new Option(vA[i],vA[i]);
  }
}

这是选择框的HTML.

<代码><;选择ID=“ sel1 ” style=“ width:125px;height:35px;margin:10px 0 10px 0;”>;<;option value=“ ”选定>;<;/option>;<;/选择>;
在我

看来很简单。

这里有一个更完整的解决方案。

代码:

<代码>函数getSelectOptions(){Var SS=SpreadsheetApp.getActive();Var sh=SS.getSheetByName('选项');Var rg=sh.getDataRange();Var va=rg.getValues();变量选项=[];for(var I=0;I<;va.length;I++){options.push(va[I][0]);}返回VA;}函数showSidebar(){Var userInterface=HtmlService.CreateHtmlOutputFromFile(' f ');SpreadsheetApp.getui().ShowModelessDialog(UserInterface,'没有选项的下拉菜单现在有了选项。');}

F.HTML

<代码><;!文档类型HTML>;<;HTML(>;)<;头部>;<;script SRC=“//ajax.googleapis.com/ajax/libs/jQuery/1.9.1/jQuery.min.JS ”>;<;/script>;<;脚本>;$(函数(){$('#txt1 ').Val(' ');Google.script.run.WithSuccessHandler(更新选择).GetSelectOptions();});函数更新选择(VA){var select=document.getElementById(“ sel1 ”);select.options.length=0;for(var I=0;I<;va.length;I++){select.options[I]=新选项(va[I],va[I]);}}console.log(“我的代码”);<;/脚本>;<;/标题>;<;身体>;<;选择ID=“ sel1 ” style=“ width:125px;height:35px;margin:10px 0 10px 0;”>;<;/选择>;<;/正文>;<;/HTML>;

下面是工作表命名的选项

enter image description here

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航