简体   繁体   English

jQuery UI 对话框剥离表单属性和非表单元素

[英]jQuery UI Dialog strips Form Attributes and Non-form Elements

Got an issue I'm not sure how to solve with jQuery.遇到一个问题,我不确定如何使用 jQuery 解决。 I've been using the jQuery UI library to make a popup with a form on it.我一直在使用 jQuery UI 库来制作一个带有表单的弹出窗口。

However the jQuery code that controls the submission of the form can't find the form because of what looks like jQuery UI Dialog is removing all the attributes from the actual form upon dialog creation.然而,控制表单提交的 jQuery 代码无法找到表单,因为 jQuery UI Dialog 在创建对话框时从实际表单中删除了所有属性。

Here is a simplified version of the popup:这是弹出窗口的简化版本:

And turning it into a dialog box with jQuery is done as follows:并用jQuery把它变成一个对话框如下:

 $("#dialog").dialog({ autoOpen: false, show: { effect: "fade", duration: 250 }, hide: { effect: "fade", duration: 250 }, draggable: false, resizable: false, width: calculatedSize, dialogClass: 'fixed-dialog', closeOnEscape: true, modal: true });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="dialog" class="about-dialog"> <div class="dialog-bg-container"> <div class="header-row"> <button id="close-button" class="dialog-close">X</button> </div> <form id="popup-form" action="api/email.php"> <input id="popup-email" class="email-input spacing-3" type="email" placeholder="Your email here" required><input id="popup-submit" class="submit-button spacing-3" type="submit" value="Sign me up!"> <div id="popup-form-alert" class="spacing-1"></div> </form> </div> </div>

Upon inspecting the code with Chrome's tools, I can see that the "id" and "action" attributes of the form are removed, as well as the div with the id of "popup-form-alert".使用 Chrome 的工具检查代码后,我可以看到表单的“id”和“action”属性被删除,以及 id 为“popup-form-alert”的 div。 If I comment out the jQuery UI code above, my form is left in-tact with no issues.如果我注释掉上面的 jQuery UI 代码,我的表单就会完好无损,没有任何问题。

One thing to keep in mind is that I do not want to use a standard jQuery UI Dialog Form as shown on their docs ( https://jqueryui.com/dialog/#modal-form ) as I need to have a custom submit button placed where I want it to be.有一点要记住的是,我希望使用标准的jQuery用户界面对话框形式显示在他们的文档( https://jqueryui.com/dialog/#modal-form ),因为我需要有一个自定义提交按钮放在我想要的地方。

Does anyone have any suggestions on how to stop jQuery stripping my form?有没有人对如何停止 jQuery 剥离我的表单有任何建议?

Many thanks!非常感谢!

After more investigation, I discovered that a duplicate dialog form was the cause of the issue.经过更多调查,我发现重复的对话框表单是问题的原因。 Upon commenting out the duplicate, the jQuery UI Dialog would preserve my form attributes.注释掉重复项后,jQuery UI 对话框将保留我的表单属性。

I'm still unsure as to why jQuery UI decides to strip the tags and would be interested in an explanation of this if anyone is able to!我仍然不确定为什么 jQuery UI 决定剥离标签,如果有人能够解释的话,我会对这个解释感兴趣!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM