我在表单外有一个表单和一个div。以前我用$(".btn-update.")click()做表格,现在用$(".btn-update").ajaxForm()不能提交表格。
html代码:
<form id="company-profile-edit-form" name="company-profile-edit-form" enctype="multipart/form-data" action="updateProfileAction.php" method="POST">
<label>
Company Name: <span class="req">*</span>
</label>
<input name="company-name" type="text" value="{companyName}" />
</form>更新配置文件
js代码:
$('.btn-update').ajaxForm({
beforeSend: function () {
$('<div class="loader"><img src="./resources/images/loader.gif" /></div>').appendTo(".main-backend .popups");
$(".loader").toggle();
},
beforeSubmit: function () {
var firstName = $("input[name=first-name]", "#company-profile-edit-form").val();
if ((email === "")) {
$('.error-message').css({
'display': 'block'
});
$(".error-message span").html('Ups! You forgot to populate fields that are required!');
$('.error-message').fadeIn('slow', function () {
$('.error-message').delay(7000).fadeOut('slow');
});
return false;
}
},
success: function (data) {
$(".loader").remove();
$("#company-profile-edit-form")[0].reset();
$(".company-profile-edit-close").remove();
$(".edit-profile").remove();
$(".op").toggle();
}
});我如何用<div class="btn-update">Update profile</div>提交这份表格?
感谢所有人
发布于 2014-02-24 15:35:10
ajaxForm必须分配给您的表单,而不是按钮。
然后,只需将一个"onclick“事件分配给您的"btn-update”(顺便说一句:对于id来说,最好避免按类提交,因为id是唯一的,而您可以将相同的类分配给多个项)和正常子类内部。
所以:
$('#company-profile-edit-form').ajaxForm({ ...和
$( '.btn-update' ).click(function() {
$('#company-profile-edit-form').submit();
});发布于 2014-02-24 15:32:42
不,你可以!
尝试将点击功能绑定到div。
<div id="update" class="btn-update">Update profile</div>而js:
$( "#update" ).click(function() {
$('#company-profile-edit-form').submit();
});记住用你的提交函数替换警报!
发布于 2014-02-24 15:34:11
https://api.jquery.com/submit/查找第一个示例:表单外部的div。答案是:
<form id="target" action="destination.html">
<input type="text" value="Hello there">
<input type="submit" value="Go">
</form>
<div id="other">
Trigger the handler
</div>
$( "#other" ).click(function() {
$( "#target" ).submit();
});https://stackoverflow.com/questions/21991859
复制相似问题