簡體   English   中英

ASP.NET JQuery .click()在IE11中不起作用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM