如何在IE中设置HTML的innerHTML下拉列表 [英] how to set the innerHTML of HTML drop down list in IE
本文介绍了如何在IE中设置HTML的innerHTML下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个html下拉列表和按钮.
I have one html drop down list and button.
<select style="width:170px" id="ddl"></select>
<input type="button" value="getvalue" onclick="abc()" />
当我单击此按钮时,我需要更改下拉列表的innerHTML.为此,我正在调用一个JavaScript函数.它可用于除IE之外的所有其他浏览器.我正在使用IE8版本.所以我不知道它是否可以在其他IE版本上使用
when i click this button , i need to change the innerHTML of drop down list.for that, i am calling one javascript fuction. it is working all other browser except IE. i am using IE8 version.so i don't know whether it will works on other IE versions
<script type="text/javascript">
function abc()
{
var a = "<option selected='selected' value='TN_Pulling'>TN_Pulling</option>";
document.getElementById('ddl').innerHTML = a;
}
</script>
请帮我解决一下.我错过了什么吗?
please help me to sort it out. did i missed anything ?
推荐答案
您的代码在我的IE11上有效,但在我的IE8上却无效.
Your code worked on my IE11, but not on my IE8.
这适用于我的IE8:
<script type="text/javascript">
function abc()
{
document.getElementById('ddl').innerHTML = ''; // clear <select> contents
var a = document.createElement('option'); // create an <option> elem
a.setAttribute('value', 'TN_Pulling'); // set 'value' attr val
a.setAttribute('selected', 'selected'); // set 'selected' attr val
a.innerHTML = 'TN_Pulling'; // set <option> contents
document.getElementById('ddl').appendChild(a); // append <option> to <select>
}
</script>
<select style="width:170px" id="ddl"></select>
<input type="button" value="getvalue" onclick="abc()" />
祝你好运.
这篇关于如何在IE中设置HTML的innerHTML下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文