【发布时间】:2015-10-13 16:45:57
【问题描述】:
我已将此作为我网站上需要验证码的表单的起点,但是在添加它后,它不会提交到 action.php 页面以移动用户。
我该怎么做才能提交?
http://jsfiddle.net/swade/M5rvh/
<form id="form" action="action.php">
<input type="text" name="name" placeholder="Name" />
<input type="submit" value="send" />
</form>
$(function(){
var mathenticate = {
bounds: {
lower: 5,
upper: 50
},
first: 0,
second: 0,
generate: function()
{
this.first = Math.floor(Math.random() * this.bounds.lower) + 1;
this.second = Math.floor(Math.random() * this.bounds.upper) + 1;
},
show: function()
{
return this.first + ' + ' + this.second;
},
solve: function()
{
return this.first + this.second;
}
};
mathenticate.generate();
var $auth = $('<input type="text" name="auth" />');
$auth
.attr('placeholder', mathenticate.show())
.insertAfter('input[name="name"]');
$('#form').on('submit', function(e){
e.preventDefault();
if( $auth.val() != mathenticate.solve() )
{
alert('wrong answer!');
}
});
});
【问题讨论】:
标签: javascript forms validation submit captcha