我得到了一些我需要更改的代碼。它是由別人建立,並不是很整齊...Javascript選項卡:致電事件onclick
有一個javascript tabcontrol,包含4個選項卡,其中包含gridviews。 所有4個gridview都是在頁面加載過程中生成的,但是我希望它們加載,當您激活選項卡時(因爲可以看到一側,而不需要特定的網格視圖)
所以,我的問題是:如何從javascript選項卡調用事件(加載gridview)?
如何突片產生:(生成的代碼,我知道,可怕的)
var obj = 0; var oid = 0; var otb = 0; var myTabs = new Array(); var myTabitems = new Array(); var myTabitem = new Array(); var myTabContent = new Array(); var myLists = new Array();function showTabContent(tab) { tb = tab.obj; id = tab.nr; if (myTabs[tb].oid != -1) { myTabs[tb].myTabContent[myTabs[tb].oid].style.display = 'none'; myTabs[tb].myTabitem[myTabs[tb].oid].className -= " active"; } myTabs[tb].myTabContent[id].style.display = 'block'; myTabs[tb].myTabitem[id].className += " active"; myTabs[tb].oid = id; }
function boTabs() { var myBlocks = new Array(); myBlocks = document.getElementsByTagName("div"); var stopit = myBlocks.length; for (var g = 0; g < stopit; g++) { if (myBlocks[g].className == "tabs") { myTabs.push(myBlocks[g]); } } var stopit2 = myTabs.length; for (var i = 0; i < stopit2; i++) { myTabs[i].myLists = myTabs[i].getElementsByTagName("ul"); if (myTabs[i].myLists[0].className == "tabs") { myTabs[i].myTabitems = myTabs[i].myLists[0].getElementsByTagName("li"); } var stopit3 = myTabs[i].myTabitems.length; myTabs[i].obj = i; myTabs[i].myTabitem = new Array(); myTabs[i].myTabContent = new Array(); for (var j = 0; j < stopit3; j++) { myTabs[i].myTabitem.push(myTabs[i].myTabitems[j]); myTabs[i].myTabitem[j].nr = j; myTabs[i].myTabitem[j].obj = i; myTabs[i].myTabitem[j].onclick = function() { showTabContent(this); }; } var myTabDivs = myTabs[i].getElementsByTagName("div"); for (var j = 0; j < myTabDivs.length; j++) { if (myTabDivs[j].className == "tabcontent") { myTabs[i].myTabContent.push(myTabDivs[j]);
} } myTabs[i].myTabitem[0].className += " active"; myTabs[i].myTabContent[0].style.display = 'block'; myTabs[i].oid = 0; myTabDivs = null; } myBlocks = null;
} 的onload = boTabs;
好吧,GridView控件在後面的代碼(C#)的約束,因此它贏得了」用JS構建...我設法使用Jquery和CSS製作tabcontrol。我將在下面發佈它作爲答案... 此時,所有4個gridviews都綁定在Page_Load上,但是,因爲花費時間在gridview後面運行te sproc,所以需要幾秒鐘的時間。因此我想在tabclick上加載它們... UpdatePanel似乎是最好的方法... – Joris 2010-04-26 21:29:59
是的,它非常方便;並且您可以在隱藏字段中存儲選項卡的選定索引,以瞭解要加載哪個網格。 – 2010-04-26 22:46:11