简体   繁体   English

我可以在多个 select 下拉菜单中使用相同的选项元素吗?

[英]Can I use the same option elements in multiple select drop downs?

I'm trying to find a way to use the same list of options for multiple select drop downs in a table.我正在尝试找到一种方法来为表格中的多个 select 下拉列表使用相同的选项列表。 I have to use the same drop down 15 times for a form but I don't want the code to have the same big statement repeated 15 times in the code:我必须对表单使用相同的下拉菜单 15 次,但我不希望代码在代码中重复 15 次相同的大语句:

 <select id="RangeDD" style="border: 0px; outline: 0px; width: 100%"> <option value="" selected disabled hidden></option> <option value="VeryLow">Very Low</option> <option value="Low">Low</option> <option value="LowAverage">Low Average</option> <option value="Average">Average</option> <option value="HighAverage">High Average</option> <option value="Superior">Superior</option> <option value="VerySuperior">Very Superior</option> <option value="NotAdministered">Not Administered</option> </select>

If there is a way to do this without using JavaScript that would be preferred.如果有办法在不使用 JavaScript 的情况下做到这一点,那将是首选。 The site I'm building in has JavaScript stored in a different area and will not let me simply put <script> tags in my code.我正在构建的站点将 JavaScript 存储在不同的区域,并且不会让我简单地将<script>标签放在我的代码中。

You could try using a virtual include statement, if your site allows it.如果您的站点允许,您可以尝试使用虚拟包含语句。

Create a document called options.html, with just the code for the options in it:创建一个名为 options.html 的文档,其中仅包含选项的代码:

<option value="" selected disabled hidden></option>
<option value="VeryLow">Very Low</option>
<option value="Low">Low</option>
<option value="LowAverage">Low Average</option>
<option value="Average">Average</option>
<option value="HighAverage">High Average</option>
<option value="Superior">Superior</option>
<option value="VerySuperior">Very Superior</option>
<option value="NotAdministered">Not Administered</option>

Then add the include statement to your main page wherever you want the select drop-down to appear:然后将 include 语句添加到您希望 select 下拉列表出现的主页:

<select id="RangeDD" style="border: 0px; outline: 0px; width: 100%">
   <!--#include virtual="options.html"-->
</select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM