简体   繁体   English

Window.prompt() 正在提交我的公式

[英]Window.prompt() is submitting my formulary

I've got a form and inside it a button that prompts a window like this:我有一个表单,里面有一个按钮,提示这样的窗口:

<form action="X">
    <!-- Some other fields -->
    <script type="text/javascript">
        window.prompt("SOME TEXT", $var);
    </script>
    <!-- Submit button of the form -->
</form>

The window's purpose is to make the user able to copy a text (which is inside the variable) pressing CTRL+C and then, close the window by hitting ENTER or ESCAPE.该窗口的目的是让用户能够按 CTRL+C 复制文本(在变量内),然后按 ENTER 或 ESCAPE 关闭窗口。

My trouble is that when I close the window, doesn't matter how (clicking on "Accept", "Cancel" or pressing ENTER or ESCAPE), my form is submitted.我的问题是,当我关闭窗口时,无论如何(单击“接受”、“取消”或按 ENTER 或 ESCAPE),我的表单都会提交。

I appreciate so much your help,我非常感谢你的帮助,

Best.最好的事物。

EDIT:编辑:

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form action="#"> <button id="copiar" style="margin-left: 65px;" onclick="copyToClipboard('Copy this')">'Button'</button> <script type="text/javascript"> function copyToClipboard(text) { window.prompt("Para copiar las etiqetas pulsa Ctrl+C, Enter", text); } $(document).ready(function() { $(document).keyup(function(e) { if(e.which == 13) { e.preventDefault(); e.stopPropagation(); return false; } }); }); </script> </form>

<button id="copiar" style="margin-left: 65px;" onclick="copyToClipboard('Copy this')">'Button'</button>

That is a submit button.那是一个提交按钮。 It is supposed to submit the form.它应该提交表格。 This has nothing to do with the prompt .这与prompt无关。

Use a plain button.使用普通按钮。 Add type="button" .添加type="button"

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

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