jQuery-取消表单提交(使用"return false"吗?)? [英] jQuery - Cancel form submit (using "return false"?)?
问题描述
在尝试取消提交表单时,我遇到了麻烦.我一直在遵循本教程(即使我没有制作登录脚本),但似乎对他有用.
I'm running into a bit of trouble while trying to cancel the submit of a form. I've been following this tutorial (even though i'm not making a login script), and it seems to be working for him.
这是我的表格:
<form action="index.php" method="post" name="pForm">
<textarea name="comment" onclick="if(this.value == 'skriv här...') this.value='';" onblur="if(this.value.length == 0) this.value='skriv här...';">skriv här...</textarea>
<input class="submit" type="submit" value="Publicera!" name="submit" />
</form>
这是jquery:
$(document).ready(function() {
$('form[name=pForm]').submit(function(){
return false;
});
});
我已经在标题中导入了jQuery,并且我知道它正在工作.我首先想到的是它可能已过时,但实际上只是一年前.
I've already imported jQuery in the header and i know it's working. My first thought was that it might be outdated, but it's actually "just" a year ago.
那么有人看到错了吗?
谢谢.
据我了解,中止提交的最简单,最适当的方法是返回假?但是我似乎无法正常工作.我在论坛上进行了搜索,发现了几个有用的主题,但实际上没有一个有用.我一定是在搞砸.
From what i've read the easiest and most appropriate way to abort the submit is to return false? But i can't seem to get it working. I've searched the forum and i've found several helpful threads but none of them actually works. I must be screwing something up.
推荐答案
尝试使用 event.preventDefault
$(document).ready(function(event) {
$('form[name=pForm]').submit(function(event){
event.preventDefault();
//add stuff here
});
});
这篇关于jQuery-取消表单提交(使用"return false"吗?)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!