我有登錄表單,其中有兩個按鈕 - 「login」和「忘記密碼?我需要檢查用戶點擊了哪個按鈕。
<form id="loginForm">
<div class="login-error" id="login-error"></div>
<input type="text" id="email" name="email">
<input type="password" id="password" name="password">
<input type="submit" name="submit" value="Login">
<button type="submit" name="submit" value="Forgot password?">Forgot password?</button>
</form>
的var_dump($ _ POST)說:
array(2) { ["email"]=> string(0) "" ["password"]=> string(0) "" }
我想兩者兼得(輸入類型=提交和按鈕類型=提交),但沒有人送 「提交」 值。
(我使用jQuery的AJAX)
$("#loginForm").click(function(){
/* Stop form from submitting normally */
event.preventDefault();
/* Get some values from elements on the page: */
var values = $(this).serialize();
/* Send the data using post and put the results in a div */
$.ajax({
url: "login.php", /* here is echo var_dump($_POST); */
type: "post",
data: values,
success: function(data){
$("#login-error").html(data);
},
error:function(){
$("#result").html('There is error while submit');
}
});
});
請你知不知道哪裏出了問題,可以嗎?我知道,關於按鈕的價值有很多線索,但沒有任何適用於我的作品。我也試過這個例子: http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_button_value2
值屬性會顯示您的網頁上的按鈕的名稱是不是?它不被視爲像其他領域一樣的價值。但是你可以做到這一點 –
不,在按鈕上按照傳統的方式使用value屬性來傳遞一個值。這是因爲按鈕以傳統方式使用 – Chris
以防萬一您還沒有閱讀此內容.http://stackoverflow.com/questions/4007942/jquery-serializearray-doesnt-include-the-smit- button-that-was-0123ed –