2010-03-30 76 views
0

我正在使用ASP.Net和jQuery/jQuery UI,我試圖使用datepicker控件。它在每個頁面都可以正常工作,除非必須使用彈出窗口(將新數據添加到數據庫中,然後刷新當前頁面以反映輸入的新數據)。當我使用彈出窗口時,似乎document.ready()失敗。我可以手動調用datepicker控件,添加一個點擊事件來觸發showcalendar函數,但是我想嘗試使其工作。有沒有人有任何想法,爲什麼彈出失敗document.ready()?Document.ready()彈出失敗

謝謝!

守則UserInterfaces.js腳本文件:

$(document).ready(function(){ 

$(".calendarTrigger").datepicker({showOn:'focus', showAnim: 'fadeIn', changeMonth: true, showOn:'both', buttonImage: '/images/calendar.gif', buttonImageOnly: true, changeYear: true, yearRange: '1950:2010'}); 

}); 

代碼中調用的彈出功能:

<a href="#" onclick='javascript:openWindow("/modules/prh/AI.aspx","PH","480","650","","");' 

代碼爲模態彈出窗口,我們使用:

function openWindow(url,name,height,width,left,top) 
{ 
if(!width) {width = 625}; 
if(!height){height = 625}; 
if(!left) {left = 60}; 
if(!top){top = 60};  
if (!name) {name='mk'}; 

name = name.replace(" ",""); 

if ((window.showModalDialog) && (navigator.appName!="Microsoft Internet Explorer")) 
{ 
     grayOut(true); 

     newWindow = window.showModalDialog(url,"name","dialogWidth: " + width + "px;dialogHeight: " + height + "px;resizable: 1;status: 0;scrollbars: 1;dialogLeft: " + left +"px;dialogTop: " + top + "px"); 

     if (newWindow) 
      newWindow.focus(); 

     grayOut(false); 

} 
else 
{ 
    newWindow = window.open(url,name,'width=' + width + ',height='+ height + 
    ',resizable=1,status=0,scrollbars=1,left=' + left +',top=' + top); 

    if (newWindow) 
     newWindow.focus(); 
    else 
     window.Name.focus(); 

} 
} 

function grayOut(vis, options) { 
// Pass true to gray out screen, false to ungray 
// options are optional. This is a JSON object with the following (optional) properties 
// opacity:0-100   // Lower number = less grayout higher = more of a blackout 
// zindex: #    // HTML elements with a higher zindex appear on top of the gray out 
// bgcolor: (#xxxxxx) // Standard RGB Hex color code 
// grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'}); 
// Because options is JSON opacity/zindex/bgcolor are all optional and can appear 
// in any order. Pass only the properties you need to set. 
var options = options || {}; 
var zindex = options.zindex || 50; 
var opacity = options.opacity || 70; 
var opaque = (opacity/100); 
var bgcolor = options.bgcolor || '#000000'; 
var dark=document.getElementById('darkenScreenObject'); 
    var tbody = document.getElementsByTagName("body")[0]; 
if (!dark) 
{ 
    // The dark layer doesn't exist, it's never been created. So we'll 
    // create it here and apply some basic styles. 
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917 
    var tnode = document.createElement('div');   // Create the layer. 
    tnode.style.position='absolute';     // Position absolutely 
    tnode.style.top='0px';       // In the top 
    tnode.style.left='0px';       // Left corner of the page 
    tnode.style.overflow='hidden';     // Try to avoid making scroll bars    
    tnode.style.display='none';      // Start out Hidden 
    tnode.id='darkenScreenObject';     // Name it so we can find it later 
    tbody.appendChild(tnode);       // Add it to the web page 
    dark=document.getElementById('darkenScreenObject'); // Get the object. 
} 


if (vis) 
{ 
    var pageWidth="100%"; 
    var pageHeight=getPageHeightWithScroll(); 
if (window.innerHeight>pageHeight) 
    pageHeight = window.innerHeight; 
pageHeight = pageHeight + "px"; 

    //set the shader to cover the entire page and make it visible. 
    dark.style.opacity=opaque;      
    dark.style.MozOpacity=opaque;     
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;   
    dark.style.backgroundColor=bgcolor; 
    dark.style.width= pageWidth; 
    dark.style.height= pageHeight; 
    dark.style.display='block';       
} 
else 
{ 
    dark.style.display='none'; 
} 
} 
+0

我沒有看到你的代碼中的任何地方document.ready ...我錯過了什麼? – 2010-03-30 01:05:32

+0

抱歉把它放在那裏。 – 2010-03-30 01:07:49

+0

@Seth - 這個.js文件包含在'/ modules/prh/AI.aspx'中的彈出窗口中? – 2010-03-30 01:10:03

回答

0

什麼標記你的彈出窗口,你有任何其他的JavaScript可能會導致datepicker火災前的錯誤彈出窗口?

+0

我有Firebugs jScript Debugger正在運行,並且我沒有發現任何中斷,只是似乎擊中了jQuery代碼的document.ready(),並且返回false或失敗並跳過日期選擇器初始化 – 2010-03-30 00:42:09

+0

在我的HoverIntent中有一個錯誤,直到現在沒有捕獲它,這是答案(有點)。 – 2010-03-30 04:17:36