最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to prevent form on submit behavior in jquery? - Stack Overflow

programmeradmin1浏览0评论

I need to get an .click() event and prevent form from behaving as it was initially designed and make my own changes and submit. How is it possible?

EDIT: Form input actually has an onclick defined behavior. I need to redefine it somehow.

EDIT: Some code

<form action='link' method='get'>
   <input type="image" name="name" id="id" class="class" onclick="this.form.action='some_link'" title="Title" value="" src="image.gif">
</form>

I need to get an .click() event and prevent form from behaving as it was initially designed and make my own changes and submit. How is it possible?

EDIT: Form input actually has an onclick defined behavior. I need to redefine it somehow.

EDIT: Some code

<form action='link' method='get'>
   <input type="image" name="name" id="id" class="class" onclick="this.form.action='some_link'" title="Title" value="" src="image.gif">
</form>
Share Improve this question edited Nov 17, 2010 at 17:17 Denys S. asked Nov 17, 2010 at 17:04 Denys S.Denys S. 6,53313 gold badges45 silver badges65 bronze badges 1
  • Possible duplicate of stackoverflow./questions/1263852/… or stackoverflow./questions/699065/… or many many others. – Shikiryu Commented Nov 17, 2010 at 17:10
Add a ment  | 

3 Answers 3

Reset to default 5

If you don't want it to submit the form, return false at the end of your click function. If you want to submit the form, use the form element and call the submit function on it:

$('#myFormID').submit();
$('#form').submit(function(e) {
    // Some code
});

I think it's enough.

You could use something like this (haven't tested it but it should work)

form = $("#yourform");
button = $("#yoursubmit");
button.click(function(){
             dosomething();
             form.submit();
             return false;});
发布评论

评论列表(0)

  1. 暂无评论