除了IE之外,其他所有浏览器都可以正常使用。即使在IE10中它也不想合作。任何帮助,将不胜感激。我有一个带有下拉菜单的表单,当用户进行选择时,它会显示一个不同形式的div,我们可以从中选择10种表单。现在它在IE中没有任何作用,没有控制台错误或任何东西。
脚本
var sections = {
'second': 'section2',
'third': 'section3',
'forth': 'section4',
'fifth': 'section5',
'sixth': 'section6',
'seventh': 'section7',
'eigth': 'section8',
'ninth': 'section9',
'tenth': 'section10',
'eleventh': 'section11'
};
var selection = function (select)
{
for (i in sections)
document.getElementById(sections[i]).style.display = "none";
document.getElementById(sections[select.value]).style.display = "block";
}
$("#target option")
.removeAttr('selected')
.find(':first')
.attr('selected', 'selected');
HTML
<select id="forms" onchange="selection(this);">
<option >Select an option</option>
<option value="tenth">General Inquiry</option>
<option value="second">Account Inquiry</option>
<option value="third">ARC Request</option>
<option value="forth">Contact Information Update</option>
<option value="fifth">Contact your Board</option>
<option value="sixth">Document Request</option>
<option value="seventh">Maintenance Issue Reporting</option>
<option value="eigth">Violations Reporting</option>
<option value="ninth">Closing Statement</option>
<option value="eleventh">Request for Proposal</option>
</select>
然后是11个divs
<div id="section10" style="display:none;">
<h2>General Inquiry</h2>
</div>
答案 0 :(得分:1)
你的问题证明是selection
has special meaning inside IE。
对于您的代码,IE会产生以下错误
SCRIPT5002: Function expected
这说明了这个问题。
防止此问题的解决方法是更改您的函数名称,例如
var selectionFunc = function (select){...}
并在你的标记中,
<select id="forms" onchange="selectionFunc(this);">
....
</select>
我希望它有所帮助