ASP.NET JQuery .click() 在 IE11 中不工作
ASP.NET JQuery .click() not working in IE11
以下 .click() 方法在 Chrome 中被触发而没有问题。
在 Internet Explorer 中,只有当我刷新页面 (F5) 时它才会被触发。如果我通过输入 url(或通过从其他页面点击按钮重定向)访问该页面,则不会触发 .click-method。
但是,如果我在 .click() 之前放置一个警报(“?”),它在 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>');
Container创建后脚本后:
<div id="tabsContainer"><ul id="HillbillyTabs"></ul></div>
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);
});
为了淡入淡出,我不得不将方法紧跟在选项卡的 creation-method 之后(在 .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
});
感谢您的快速回复和提示!
亲切的问候
不要尝试注入函数调用,而是向代码中添加一个事件侦听器。例如:(我编造了一些变量,因为你的代码在这里没有说明一些事情)
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);
});
以下 .click() 方法在 Chrome 中被触发而没有问题。 在 Internet Explorer 中,只有当我刷新页面 (F5) 时它才会被触发。如果我通过输入 url(或通过从其他页面点击按钮重定向)访问该页面,则不会触发 .click-method。
但是,如果我在 .click() 之前放置一个警报(“?”),它在 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>');
Container创建后脚本后:
<div id="tabsContainer"><ul id="HillbillyTabs"></ul></div>
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);
});
为了淡入淡出,我不得不将方法紧跟在选项卡的 creation-method 之后(在 .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
});
感谢您的快速回复和提示!
亲切的问候
不要尝试注入函数调用,而是向代码中添加一个事件侦听器。例如:(我编造了一些变量,因为你的代码在这里没有说明一些事情)
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);
});