[英]ASP.NET JQuery .click() not working in IE11
在Chrome中触发了以下.click()方法,不会出现问题。 在Internet Explorer中,只有刷新页面(F5)才会触发。 如果我通过输入url(或通过其他页面的buttonclick重定向)访问页面,则不会触发.click方法。
但是,如果我在.click()之前放置了alert(“?”),它也可以在IE中使用!
为什么在IE中无法正常工作? 我不能让alert()在那里...
$(window).load(function() {
//Fake click on the last used Tab
alert("?");
$("#"+GetCookie("lastTab["+window.location.pathname+"]")).click();
});
=>在以下位置创建可用(可单击)选项卡
jQuery(document).ready(function($) {
...
});
编辑从评论:
它们是通过以下方式在.read(function($)
内创建的:
$("#HillbillyTabs").append('<li><a href="#Tab' + upperIndex + '" id="TabHead' + upperIndex + '" onclick="SetCookie(this.id);">' + title + '</a></li>').after('<div id="Tab' + upperIndex + '"></div>');
在脚本之后创建容器之后:
<div id="tabsContainer"><ul id="HillbillyTabs"></ul></div>
不要尝试注入函数调用,而要在代码中添加事件监听器。 例如:(我编写了一些变量,因为您的代码未在此处指示某些内容)
var upperIndex = $('#tabsContainer').find('ul').length;
var title = "mytitle";
var newHeadId = 'TabHead' + upperIndex;
var newTabId = 'Tab' + upperIndex;
$("#HillbillyTabs").append('<li><a href="#' + newTabId + '" id="' + newHeadId + '">' + title + '</a></li>').after('<div id="' + newTabId + '"></div>');
$("#HillbillyTabs").on('click', '#' + newHeadId, function() {
console.log(this.id);
SetCookie(this.id);
});
看来IE无法识别:
$(window).load()
您可以尝试:
window.onload = function() {
$("#"+GetCookie("lastTab["+window.location.pathname+"]")).click();
};
得到了解决方案。
奇怪的是,.load中的fadeIn也不适用于IE(例如.click)
$(window).load(function() {
//Fake click on the last used Tab
alert("?");
$("#"+GetCookie("lastTab["+window.location.pathname+"]")).click();
// When the page has loaded in Chrome
$("#DeltaPlaceHolderMain").fadeIn(0);
});
为了淡入淡出,我不得不将方法立即放在选项卡的创建方法之后(在.ready()内)而不是.ready()的末尾。
现在还有.click,它现在适用于IE。
jQuery(document).ready(function($) {
setTimeout(function() {
...
//Creation of tabs
$("#tabsContainer").tabs();
//Fake click on the last used Tab
$("#"+GetCookie("lastTab["+window.location.pathname+"]")).click();
// When the page has loaded in IE
$("#contentBox").fadeIn(0);
}, 0);
//.click NOT here
});
感谢您的快速回复和提示!
亲切的问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.