【问题标题】:Trigger function when button is clicked but before submission单击按钮但在提交之前触发功能
【发布时间】:2019-01-22 14:06:23
【问题描述】:

在提交之前,我正在将一个所见即所得编辑器的内容换成另一个。我一直在通过将提交按钮包装在 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 方法并尝试忘记它

非常感谢!

【问题讨论】:

    标签: jquery forms onsubmit mouseenter


    【解决方案1】:

    尝试从您的按钮中删除 onclick 并使用此 jquery。这是假设您的按钮在表单中。

    $(document).on("click","#sq_commit_button",function() {
      // your pre submit code here
      $(this).parents("form").submit();
    });

    【讨论】:

    • 伴侣,实际上工作得很好,谢谢您的意见
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多