【发布时间】:2012-08-07 16:30:43
【问题描述】:
我正在尝试使用 jquery 从表单中获取数据并使用此代码停止表单提交:
$form = $('form#signup')
$form.submit(function(event){
event.preventDefault();
var $input=$('#signup :input')
console.log($input.username)
alert($input.username)
})
但是表单仍然posts 的数据和警告框没有出现。而且firebug 提出了错误$ is not defined 和Node.js 崩溃
形式(玉写):
html
head
script(src='javascripts/signupValidation.js')
script(src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js')
script(src='javascripts/validator.js')
body
form(id='signup',method='post',action='/signup')
label Firstname
input(type='text', name='firstname')
label Lastname
input(type='text', name='lastname')
label Username
input(type='text', name='username')
label Password
input(type='password', name='password')
label Password again
input(type='password', name='password2')
label Email
input(type='email', name='email')
input(type='submit',value='Sign up', onclick="")
【问题讨论】:
-
NITPICK:使用分号!不使用它们是不好的做法,如果你想压缩你的代码,你将需要它们。
标签: javascript jquery pug