2013-07-02 2 views
0

나는 다음과 같은 한 마크 업. 여기에 마크 업,JQuery와 열려있는 대화

<asp:Repeater ID="Repeater1" runat="server" > 
    <HeaderTemplate> 
    <table cellpadding="5" cellspacing="0" > 
    <tr align="center" > 
     <th align="center"><span><a href="#" style="color:Blue;background-color:#f2f2f2;" >Open Dialog</a></span></th> 
    </tr> 
    ....... 
</asp:Repeater> 

나는 JQuery와 기능 대화 상자를 열 수 있지만 작동하지 않도록 다음과 같은 노력하고있어

$("th span a").click(function (e) { 
      e.preventDefault(); 
      var targetUrl = $(this).attr("href"); 

      $("#dialog").dialog({ 
       buttons: { 
        "Close": function() { 
         $(this).dialog("close"); 
        } 
       } 
      }); 

      $("#dialog").dialog("open"); 
     }); 

무슨 일이없는 어떤 생각인가?

+0

아니라 우선, 옵션'에 AutoOpen 설정하지 않음으로써 : FALSE '를, 당신은 두 번 열려고하고 있습니다. 기록으로, 당신은 선이 필요하지 않습니다'$ ("# 대화 상자") 대화 상자 ("열기"). '그러나, 아마도 그것을두고하는 것이 현명하고 시도 –

+0

클릭 이벤트의 당신의 대화 초기화 외부를 이동할 것 'dialog' 앞에'ContentPlaceHolder_'를 추가하십시오. – PiLHA

답변

2

첫째로, 당신은 ID dialog 인 요소를 가지고 있습니까? 둘째, 이미 클릭 이벤트에서 열린 대화 상자를 만든 다음 다시 열려고합니다. 나는이 같은 재 제안 : 대화 doesnt이 이미 존재하는 경우

$(function() { 
    $(document).on('click', 'th span a', function(e) { 
     e.preventDefault(); 
     var targetUrl = $(this).attr("href"); 
     $("#dialog").dialog("open"); 
    }); 

    $('#dialog').dialog({ 
     autoOpen: false, 
     buttons: { 
      'Close': function(e, ui) { 
       $(this).dialog('close'); 
      } 
     } 
    }) 
}) 

을, 다음으로 재 작성 수 : 물론

<script type="text/javascript"> 
    var dlg; 
    $(function() { 
     $(document).on('click', 'th span a', function(e) { 
      e.preventDefault(); 
      var targetUrl = $(this).attr("href"); 
      dlg.dialog("open"); 
     }); 

     dlg = $('<div />', { id: 'dialog' }).dialog({ 
      autoOpen: false, 
      buttons: { 
       'Close': function(e, ui) { 
        $(this).dialog('close'); 
       } 
      } 
     }) 
    }) 
</script> 

이 두 번째 방법은 생성하고 대화에 HTML을 추가 의미 DIV, 그렇지 않으면 그것은 비어있을 것입니다 ... 영원히!

+0

@ bilbob533 감사합니다. 귀하의 코드는 잘 작동합니다. 예 저는 대화 ID가있는 요소가 있습니다. – Rishi