[英]javascript not working on ie8 -type mismatch
JavaScript not working on IE8 -getting type mismatch on this particular line: JavaScript无法在IE8上运行-在此特定行上获取类型不匹配:
from_s.add(temp, from_s.options[0]);
I have run this search/display code on Firefox and higher version of ie's and it worked perfectly fine. 我已经在Firefox和ie的更高版本上运行了此搜索/显示代码,并且运行良好。 I just don't get it, =(( i really really need this one to work, I hope someone out there could help me =( 我只是不明白,=((我真的很需要这个,我希望那里有人可以帮助我=(
Here is my code that searches for a keyword and puts it on top of the list: 这是我的代码,该代码搜索关键字并将其放在列表的顶部:
JavaScript: JavaScript的:
<script type="text/javascript">
function searchstudent(){
var searchvalue= document.getElementById('search').value;
var from_s = document.getElementById('students-out');
for (var i=0;i<from_s.options.length-1;i++){
var st = from_s.options[i].text;
if(st.search(searchvalue)>-1){
var temp = from_s.options[i];
from_s.add(temp, from_s.options[0]);
}
}
}
and the form: 以及形式:
<form id="search2">
<input type="text" id="search" onkeyup="searchstudent()" placeholder="Enter Keyword here.. ." /><br/><br/><br/>
<select name="users-out" id="students-out" multiple="multiple" size="10" onchange="location = this.options[this.selectedIndex].value;">
<option value="n.html" title="ppp">ppp</option>
<option value="n.html" title="ppp">yyy</option>
<option value="g.html" title="qwe">qwe</option>
<option value="32" title="bond desk">bond desk</option>
<option value="32" title="qqq">qqq</option>
<option value="26" title=" "> </option>
</select>
</form>
It looks like add()
does not exist on HTMLSelectElement
in IE8. 看来IE8中的HTMLSelectElement
上不存在 add()
。
Instead you could probably use the much more consistent and standardized insertBefore()
DOM Node method. 相反,您可能会使用更加一致和标准化的insertBefore()
DOM Node方法。
from_s.insertBefore(temp, from_s.options[0]);
Or appendChild()
if you want it at the end. 或如果需要结尾则appendChild()
。
See also: JavaScript Error in add method using IE8 另请参阅: 使用IE8的添加方法中的JavaScript错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.