使用jQuery从表单外部的链接提交表单 [英] Using jQuery to submit form from link outside of form

查看:135
本文介绍了使用jQuery从表单外部的链接提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过位于导航栏中的链接提交表单。

I'm trying to submit a form from a link that is located in my nav bar.

我是javascript.jQuery的新手并且不确定为什么这会赢执行。

I'm new to javascript.jQuery and unsure why this won't execute.

我有一种感觉,我需要在链接的href中添加其他东西,但我不确定它是什么?我很感谢您的反馈和专业知识。

I have a feeling there I need to put something else in the link's href but I'm not sure what it is? I appreciate the feedback and expertise.

LINK

<li><a href="#" id="add-product-save-link"><i class="icon-plus"></i> Save</a></li>

FORM

<form class="form" action="" method="post" id="add-product-form">

JAVASCRIPT(此代码位于我已链接到模板的外部单独文件中)

JAVASCRIPT (this code in an external separate file I have linked to the template)

$(document).ready(function() { 
    $('#add-product-save-link').click(function(e) {
        e.preventDefault();
        $('#add-product-form').submit();
    });
});

我已经链接到jQuery:

I've linked to jQuery with:

推荐答案

:( http://jsfiddle.net/4enf7/

<a href="javascript:document.getElementById('add-product-form').submit();">Send form</a>

这篇关于使用jQuery从表单外部的链接提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆