2012-07-07 121 views
1

我的aspx標記是簡單,JQUERY:如何顯示超鏈接點擊彈出窗口?

<div class="sm08" id="dialog" title="Dialog Title"><asp:Literal ID="litTerms" runat="server"></asp:Literal></div> 

<asp:HyperLink ID="hp" runat="server" NavigateUrl="#">HyperLink</asp:HyperLink> 

我如何可以加載超鏈接彈出的點擊? 當前彈出窗口顯示在頁面加載。

<script type="text/javascript"> 
    $(document).ready(function() { 
     $("#dialog").dialog({modal: true, buttons: { "Ok": function() { $(this).dialog("close"); } }}); 
    }); 
    </script> 

預先感謝您

回答

1

試試這個:

$(document).ready(function() { 
    $('#hp').on('click', function(e){ 
     e.preventDefault() // prevents the default action of the anchor link 
     $("#dialog").dialog({modal: true, buttons: { "Ok": function() { $(this).dialog("close"); } }}); 
    }) 
}); 
+0

你好,你確定嗎? – OrElse 2012-07-07 19:11:04

+0

@ Chocol8你好,這應該工作。 – undefined 2012-07-07 19:12:40

1

添加點擊監聽到你的鏈接:

$('#hp').click(function(e){ 
    e.preventDefault(); 
    $('#dialog').dialog('open'); 
}); 

此外,您將需要設置 '的AutoOpen'爲'false:

$("#dialog").dialog({autoOpen: false, modal: true, buttons: { "Ok": function() { $(this).dialog("close"); } }}); 
相關問題