使用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>