2013-04-22 18 views
0

每次有人點擊取消註冊按鈕,有一個確認對話框,但當我點擊沒有任何迴應。我也嘗試通過在pade加載時提供淡入淡出效果來實現jquery效果,但也沒有任何響應。我保存頁面ini .php擴展名。Javascript確認和jQuery的fadein沒有響應

<html> 
    <head> 
    <title>Home</title> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> 
    </script> 
    <script type="text/javascript"> 
    $(document).ready(function(){ 
     $("*").fadeIn(4000); 
    }); 
    function confirm() { 
     var answer = confirm("Are you sure you want to register?") 
     if (answer){ 
     window.location = "unregister.php"; 
     } 
     else{ 
     alert("Thanks for sticking around!") 
     } 
    } 

    </script> 
    </head> 
    <body> 
    <p> 
    <form id="form2" name="form2" method="post"> 
    <a href="logout.php"><button>Logout</button></a> 

     <a href="form.php"><button>Add New record</button></a> 
     <a href="register.php"><button>Edit Profile</button></a> 
     <input type="button" onClick="confirm()" value="Unregister"> 
     </form> 
    </p> 
    .... 

回答

2

confirm()是一個JavaScript函數,那麼請嘗試更改以下:

<input type="button" onClick="confirm()" value="Unregister"> 

<input type="button" onClick="return ask_confirm();" value="Unregister"> 

而且

function ask_confirm() { 
     var answer = confirm("Are you sure you want to register?") 
     if (answer){ 
     window.location = "unregister.php"; 
     } 
     else{ 
     alert("Thanks for sticking around!") 
     } 
} 
+0

+1,打我吧:) – MatthewMcGovern 2013-04-22 10:56:34

0

你的函數確認必須返回true或發LSE

function confirm() { 
    var answer = confirm("Are you sure you want to register?") 
    if (answer){ 
    window.location = "unregister.php"; 
    return true; 
    } 
    else{ 
    alert("Thanks for sticking around!"); 
    return false; 
    } 
} 
0

你忘了 「HTTP:」 前綴:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> 
+0

不,這不是必須的https://developers.google.com/speed/libraries/devguide?hl=zh-TW#jquery – 2013-04-22 11:08:39

1

的Sudhir是關於確認功能正確。

你的fadeIn不做任何事的原因是因爲它隻影響隱藏的元素。

如果您確實希望淡入整個頁面,您需要在調用fadeIn之前添加:$("*").hide();

編輯:請注意,大多數人不喜歡使用$("*"),因爲它會從字面上選擇所有可能導致問題的東西。例如,當我測試隱藏一切,然後使用fadeIn,它使我所有的進度欄和加載gifs可見。

一個更好的解決辦法是:

$("html").hide(); 
$("html").fadeIn(4000); 

這樣的頁面看起來幾乎完全應該如何,不顯示的東西,你希望留隱患。