簡體   English   中英

如何使用 asp.net 中的鏈接按鈕調用 JQuery 對話框

[英]How to call JQuery dialog box using link button in asp.net

我的網站上有一個 Jquery 對話框。 此對話框用於獲取用戶評論。 目前,我正在使用以下代碼執行 Javascript function 並且工作正常:

**<a href="#dialog" name="modal">Rate this</a>**

<div id="dialog" class="window"></div>
<div id="mask"></div> 

它調用的 Javascript 代碼如下:

 $(document).ready(function() {

        //select all the a tag with name equal to modal

        $('a[name=modal]').click(function(e) {
            //Cancel the link behavior
            e.preventDefault();
            //Get the A tag
            var id = $(this).attr('href');

            //Get the screen height and width
            var maskHeight = $(document).height();
            var maskWidth = $(window).width();

            //Set heigth and width to mask to fill up the whole screen
            $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

            //transition effect     
            $('#mask').fadeIn(1000);
            $('#mask').fadeTo("slow", 0.8);

            //Get the window height and width
            var winH = $(window).height();
            var winW = $(window).width();

            //Set the popup window to center
            $(id).css('top', winH / 2 - $(id).height() / 2);
            $(id).css('left', winW / 2 - $(id).width() / 2);

            //transition effect
            $(id).fadeIn(2000);

        });

    });

    //if close button is clicked

    $("input[id$='btnClose']").click(function(e) {
                   e.preventDefault();

        $('#mask').hide();
        $('.window').hide();
    });

由於 href 沒有服務器端點擊事件,我需要使用鏈接按鈕調用 javascript。 我嘗試了幾種方法,但未能得到實際結果。

最后,我需要將此調用**<a href="#dialog" name="modal">Rate this</a>**更改為鏈接按鈕,以便我可以捕獲點擊事件。

您可以使用 RegisterStartupScript 執行此操作,它允許您在服務器端調用結束時運行 Javascript。 可以在此處找到示例 > http://www.dotnetcurry.com/ShowArticle.aspx?ID=200

說我強烈建議您甚至在用戶單擊之前嘗試操作鏈接,即當頁面加載時,而不是將錨標記轉換為鏈接按鈕。

當頁面加載時,您應該檢查請求的客戶端是否是注冊用戶。 如果他顯示相同的**<a href="#dialog" name="modal">Rate this</a>**並在

<div id="dialog" class="window">//Rating stuff goes here</div>

如果您看到該用戶未注冊,那么您可以隱藏鏈接或將模態div更改為顯示,您未注冊,請點擊此處注冊。

希望它有意義。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM