单击按钮但在提交之前触发功能
Trigger function when button is clicked but before submission
我在提交之前将一个所见即所得编辑器的内容换成另一个。我一直在通过将提交按钮包装在 div 中并使用 mouseenter 事件来触发它来做到这一点。
<div id="moveit">
<input type="button" name="sq_commit_button" id="sq_commit_button" value="Commit" accesskey="s" class="sq-form-field sq-btn-large sq-btn-green sq-commit-button" onclick="if (submit_form) { submit_form(this.form); } else { this.form.submit(); this.disabled = 'disabled';} ">
</div>
和
jQuery('#moveit').mouseenter(function() {
jQuery('#news_item_0_1162_wysiwyg_div #htmlarea iframe').contents().find('html').html(jQuery('#cke_1_contents iframe').contents().find('html body').html());
});
目前效果还不错,但绝不是一个长期的解决方案。有没有一种方法可以在单击按钮但提交之前执行该功能,以便可以复制内容?
我试过使用 onsubmit 函数,但是当我看时,所见即所得的编辑器似乎不包含任何表单元素。
$('#myform').submit(function() {
// your code here
});
页面上唯一的表单实例如下所示,我在 onsubmit 函数中尝试了以下表单 ID 和名称,但没有成功。
<form id="page_asset_builder_1427599" name="main_form" method="post" action="http://example.com/builder/_nocache?" enctype="multipart/form-data" onsubmit="return form_on_submit()">
谁能建议我该怎么做?或者我应该坚持使用我的 mouseenter 方法并尝试忘记它
非常感谢!
尝试从您的按钮中删除 onclick 并使用此 jquery。这是假设您的按钮在表单中。
$(document).on("click","#sq_commit_button",function() {
// your pre submit code here
$(this).parents("form").submit();
});
我在提交之前将一个所见即所得编辑器的内容换成另一个。我一直在通过将提交按钮包装在 div 中并使用 mouseenter 事件来触发它来做到这一点。
<div id="moveit">
<input type="button" name="sq_commit_button" id="sq_commit_button" value="Commit" accesskey="s" class="sq-form-field sq-btn-large sq-btn-green sq-commit-button" onclick="if (submit_form) { submit_form(this.form); } else { this.form.submit(); this.disabled = 'disabled';} ">
</div>
和
jQuery('#moveit').mouseenter(function() {
jQuery('#news_item_0_1162_wysiwyg_div #htmlarea iframe').contents().find('html').html(jQuery('#cke_1_contents iframe').contents().find('html body').html());
});
目前效果还不错,但绝不是一个长期的解决方案。有没有一种方法可以在单击按钮但提交之前执行该功能,以便可以复制内容?
我试过使用 onsubmit 函数,但是当我看时,所见即所得的编辑器似乎不包含任何表单元素。
$('#myform').submit(function() {
// your code here
});
页面上唯一的表单实例如下所示,我在 onsubmit 函数中尝试了以下表单 ID 和名称,但没有成功。
<form id="page_asset_builder_1427599" name="main_form" method="post" action="http://example.com/builder/_nocache?" enctype="multipart/form-data" onsubmit="return form_on_submit()">
谁能建议我该怎么做?或者我应该坚持使用我的 mouseenter 方法并尝试忘记它
非常感谢!
尝试从您的按钮中删除 onclick 并使用此 jquery。这是假设您的按钮在表单中。
$(document).on("click","#sq_commit_button",function() {
// your pre submit code here
$(this).parents("form").submit();
});