从页面加载下拉列表中删除项目(无jquery) [英] Remove item from dropdown list on page load (no jquery)
本文介绍了从页面加载下拉列表中删除项目(无jquery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的下拉式清单:
I have the following dropdown list:
<select name="DD1" id="DD1">
<option value="B">B</option>
<option value="D">D</option>
<option value="E">E</option>
<option value="F">F</option>
<option value="R">R</option>
</select>
在页面加载时,我需要隐藏/删除选项D.我不能按索引去该列表是动态的,所以我必须使用value参数或渲染的实际文本。
On page load I need to hide/delete option D. I can't go by the index because that list is dynamic so I have to use the value parameter or the actual text that gets rendered.
我试过找到答案,但是我遇到的所有解决方案都是使用JQuery来完成的,我没有这个选项。
I've tried finding the answer but all the solutions I came across use JQuery for this and I don't have the option to do this.
任何人都有办法在页面加载时使用Javascipt隐藏选项D,所以用户从不会看到该选项?
Anyone have a way to hide option D just using Javascipt on page load so the user never sees that option?
p>
推荐答案
var select=document.getElementById('DD1');
for (i=0;i<select.length; i++) {
if (select.options[i].value=='D') {
select.remove(i);
}
}
这篇关于从页面加载下拉列表中删除项目(无jquery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文