2011-03-21 3 views
0

나는 내 스크립트 내가이 Site.Master 페이지에서 파일을 JS 포함 한JQuery와 대화 팝업 창 문제

var window = "<div id='window' style='display: none;width:190px'></div>"; 


PopUpWindow = function (titles, message, redirectURL) { 
    document.getElementById('window').innerHTML = message; 
    $("#window").dialog({ 
     resizable: true, 
     height: 180, 
     title: titles, 
     width: 500, 
     modal: false, 
     open: function() { 
      $('.ui-widget-overlay').show(); 
      $('.ui-dialog-titlebar-close.ui-corner-all').hide(); 
     }, 
     buttons: { 
      "OK": function() { 
       $(this).dialog("close"); 
       if (redirectURL) { 
        window.location = redirectURL; 
       } 
      } 
     } 
    }); 
}; 

폴더에 .. 내 PopUpWindow.js 파일에이 코드를 추가했다.

하지만 여전히 내 aspx 페이지에서이 PopUpWindow 기능에 액세스 할 수 없습니까?

내가 뭔가를하고있는 것입니까?

나는

PopUpWindow("Field to Show","Message","URL redirect"); 

감사

에게 팝업 메시지를 표시하기위한이 PopUpWindow을 execte 수 없습니다입니다

답변

1

"window"는 변수에 보관되어 있지만 id로 가져 오기 전에는 아무 데나 페이지에 추가되지 않습니다.

var window = "<div id='window' style='display: none;width:190px'></div>"; 


    PopUpWindow = function (titles, message, redirectURL) { 

    // Add to body (change the selector to whatever's relevant) 
    $('body').append(window); 
    // Set the innerHTML the jQuery way :) 
    $('#window').html(message); 
    $("#window").dialog({ 
     resizable: true, 
     height: 180, 
     title: titles, 
     width: 500, 
     modal: false, 
     open: function() { 
      $('.ui-widget-overlay').show(); 
      $('.ui-dialog-titlebar-close.ui-corner-all').hide(); 
     }, 
     buttons: { 
      "OK": function() { 
       $(this).dialog("close"); 
       if (redirectURL) { 
        window.location = redirectURL; 
       } 
      } 
     } 
    }); 
}; 

가 난 단지 JSFiddle에이를 테스트했습니다, 그리고 CSS가없는, 그래서 내가 잘못이없는 더 보장 할 수 없습니다, 그러나 이것은 당신이 표시를 변경할 경우 나타나는 대화 상자을 수행하는 "블록" '#window'에

0

이 중이 파일의 잘못된 (나쁜 URL) 또는 뭔가를로드하여 진행되는 것으로 보인다 . 확인하고 알려주십시오. 구문 오류 일 수 있습니다.

편집 : DOM을 창에 추가하는 것을 잊어 버리셨습니까?

var window2 = "<div id='window' style='display: none;width:190px'></div>"; 

$(window2).appendTo("body") 
+0

감사합니다 Nexxeus. 내가 언급 한 코드는 js 파일에있는 코드입니다. 모든 것은 같지만이 PopUpWindow 대화 상자에 액세스 할 수 없습니까? – kumar

+0

내 편집을 보았습니까? – mattsven

+0

IF i Jsite 파일을 내 site.master 페이지에 추가합니다. 내 페이지에서이 오류가 발생했습니다. 웹 페이지 오류 세부 정보 사용자 에이전트 : Mozilla/4.0 (호환 가능, MSIE 8.0, Windows NT 6.1, WOW64, Trident/4.0, GTB0.0 , SLCC2, .NET CLR 2.0.50727, .NET CLR 3.5.30729, .NET CLR 3.0.30729, Media Center PC 6.0, MDDR, .NET4.0C, .NET4.0E) 타임 스탬프 : 2011 년 3 월 21 일 월요일 : 27 일 44 UTC 메시지 : 개체가이 속성 또는 메서드를 지원하지 않습니다 라인 : 5 문자 : 71,822 코드 : 0 URI : HTTP : // 로컬 호스트 : 50189/스크립트/MicrosoftAjax.js 메시지 : w ' .document '가 null이거나 객체가 아닙니다. Line : 7 – kumar