我有登录表单,其中有两个按钮 - “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 –