如果控制台关闭,Javascript 在 Internet Explorer 上不起作用
Javascript not working on Internet Explorer if console is closed
我正在用一些JavaScript编程一个菜单。 它在Chrome或Firefox上工作正常,但在Internet Explorer上则不然。好吧,仅当打开IE中的控制台时,它才会这样做。如果我再次关闭它,它不起作用。我读过它可能与console.log
有关;但我的文件中没有任何console.log
文本。
更新:IE版本:11
这是我的Javascript和HTML代码:
<div class="cuenta-menu logged">
<div class="cuenta">
<a href="#cuenta-menu-cuenta" class="c-menu c-menu-cuenta" onclick="setActive(0);return false;">
<p>
Cuenta
</p>
</a>
</div>
<div class="facturaciones">
<a href="#cuenta-menu-facturaciones" class="c-menu c-menu-facturaciones" onclick="setActive(1);return false;">
<p>
Facturación
</p>
</a>
</div>
<div class="direcciones">
<a href="#cuenta-menu-direcciones" class="c-menu c-menu-direcciones" onclick="setActive(2);return false;">
<p>
Direcciones
</p>
</a>
</div>
<div class="pedidos">
<a href="#cuenta-menu-pedidos" class="c-menu c-menu-pedidos" onclick="setActive(3);return false;">
<p>
Pedidos
</p>
</a>
</div>
</div>
<div id="cuenta-menu-cuenta" class="c-menu-content">
Contingut información de la cuenta
</div>
<!-- Search -->
<div id="cuenta-menu-facturaciones" class="c-menu-content">
<h1>Contingut facturaciones</h1>
<div>
</div>
</div>
<!-- Account -->
<div id="cuenta-menu-direcciones" class="c-menu-content">
Contingut direcciones
</div>
<!-- Cart -->
<div id="cuenta-menu-pedidos" class="c-menu-content">
Contingut pedidos
</div>
<script>
function detectIE() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
// IE 11 => return version number
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
var edge = ua.indexOf('Edge/');
if (edge > 0) {
// Edge (IE 12+) => return version number
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
}
// other browser
return false;
}
function isActive(act)
{
if(detectIE()) {
if(act.getAttribute('class').indexOf('c-menu-active')>-1)
return true;
else
return false;
}
else {
if(act.getAttribute('class').includes('c-menu-active'))
return true;
else
return false;
}
}
function setActive(numero)
{
var skiplink = document.getElementsByClassName('c-menu')[numero];
if(isActive(skiplink))
{
setNonActive(skiplink);
}
else
{
setNonActives();
setIsActive(skiplink);
}
}
function setNonActives()
{
var skiplinks = document.getElementsByClassName('c-menu');
for(i=0;i<skiplinks.length;i++)
{
setNonActive(skiplinks[i]);
}
}
function setIsActive(act)
{
act.setAttribute('class',act.getAttribute('class') + ' c-menu-active');
var idelem = document.getElementById(act.getAttribute('href').replace('#',''));
idelem.setAttribute('class',idelem.getAttribute('class') + ' c-menu-active');
}
function setNonActive(act)
{
act.setAttribute('class',act.getAttribute('class').replace(' c-menu-active',''));
var idelem = document.getElementById(act.getAttribute('href').replace('#',''));
idelem.setAttribute('class',idelem.getAttribute('class').replace(' c-menu-active',''));
}
$(document).ready(function(){
$('#logout_a').click(function(){
window.location.href='home.php';
});
});
</script>
如何在控制台关闭的情况下使其在IE中工作?
我最终通过抛出jQuery而不是DOM,现在它可以在任何浏览器中工作。
相关文章:
- 视频HTML没有'无法在Internet Explorer 11上工作
- Internet Explorer缺少占位符支持,特别是密码字段
- Internet Explorer中的文本换行错误
- 为什么我在Internet Explorer上看不到html元素
- internet explorer 8兼容模式下的Youtube api错误
- 当浏览器控制台未打开时,为什么要求会导致Internet Explorer 9超时
- Internet Explorer 8. Events
- jQuery表单验证适用于Mozilla和Internet Explorer,但不适用于Chrome或Safari
- element.dataset in Internet Explorer
- Facebook FB.init”;访问被拒绝”;在Internet Explorer 11中
- JavaScript不适用于internet explorer和Firefox,但适用于谷歌
- 在Internet Explorer中,向所选内容添加选项不起作用
- 在Internet Explorer中从二进制文件打开PDF
- elementproblem internet explorer
- 我可以使用哪些方法在Internet Explorer中禁用Alt+*X*
- 如何在Internet Explorer中使用javascript设置cookie
- 只有当alert()在带有AJAX的internet explorer中使用时,Javascript才会更新UI
- sharepoint站点的internet explorer中出现Javascript错误
- Internet Explorer重新加载IFrame
- 如何在不使用Internet Explorer的情况下从未挂起的HTML文件执行程序