Php 未调用jquery$(“表单”).submit()
我在一个页面上有一个表单,如果用户在数据库中设置了阻止属性,则需要验证码Php 未调用jquery$(“表单”).submit(),php,jquery,recaptcha,Php,Jquery,Recaptcha,我在一个页面上有一个表单,如果用户在数据库中设置了阻止属性,则需要验证码 $("#expressform").submit(function() { if($("#op").val() == "") return false; if($("#tagbar").val() == "") return false; $.post("getallowed.php", function(data) { if(
$("#expressform").submit(function() {
if($("#op").val() == "")
return false;
if($("#tagbar").val() == "")
return false;
$.post("getallowed.php", function(data) {
if(data == "true")
submitNormal();
else if(data == "false"){
displayCaptcha();
}
});
return false;
});
如果不允许用户,则调用displayCaptcha函数,而不仅仅是提交表单
function displayCaptcha(){
$.post("expresscaptcha.php", function(data) {
var string = data;
$("#expressformdiv").html(string);
Recaptcha.create("xxxxxxxxxxx", "captcha",
{
theme: "red",
callback: Recaptcha.focus_response_field
}
);
});
}
此函数将发布到一个php脚本,该脚本返回一种新类型的表单,该表单返回id为expressformcaptcha的新表单的html。下面是php脚本
<?php
echo <<<_END
<form id="expressformcaptcha">
//other form elements
<div id="captchadiv"><div id="captcha"></div></div>
</form>
_END;
?>
这与jquery中的验证码有关吗?提交表单时,页面只会刷新,而不是警报。您需要使用或,因为expressformcaptcha
稍后会被注入DOM
$("#expressformcaptcha").live('submit', function() {
alert("FORM SUBMITTED");
});
您需要在以后将expressformcaptcha
注入DOM时使用或
$("#expressformcaptcha").live('submit', function() {
alert("FORM SUBMITTED");
});
工作!非常感谢。如果我可能会问,为什么我必须使用live?这是因为在绑定事件时,DOM中不存在该元素。有机会时请标记为已接受,谢谢!你不必使用live;他提到代表是另一个选择!在某些情况下,这无关紧要,但一般来说.delegate()要好得多(处理事件传播更好,由于侦听的元素更少,所以执行得更好);在.live()也可以工作的情况下,我会养成使用.delegate()的习惯!非常感谢。如果我可能会问,为什么我必须使用live?这是因为在绑定事件时,DOM中不存在该元素。有机会时请标记为已接受,谢谢!你不必使用live;他提到代表是另一个选择!在某些情况下,这无关紧要,但一般来说.delegate()要好得多(处理事件传播更好,由于侦听的元素更少,所以执行得更好);在.live()也可以工作的情况下,我会养成使用.delegate()的习惯。