zoukankan      html  css  js  c++  java
  • HTML 之 Web页面表单form中只有一个input的text元素,按回车默认提交

      WEB开发中,如果页面的 form 中只有一个input元素,在该input元素的输入框中按回车(注:此时并没有写对应的onkeydown等事件处理),则浏览器会默认提交表单,请看如下代码:

    <html>  
        <head>  
           <title>页面中只有一个input元素时默认提交表单</title>  
        </head>  
        <body>  
             <form action="http://www.baidu.com" name="myform" method="get">  
                <input name="contenta" type="text" value="回车提交" /></br>  
             </form>  
        </body>  
    </html>  

    那么如何禁止呢,禁止方法有两种:

    [1]只有一个时发生,可以在form中添加一个隐藏的input元素,修改后的代码如下:

    <html>  
        <head>  
           <title>页面中只有一个input元素时默认提交表单</title>  
        </head>  
        <body>  
             <form action="http://www.baidu.com" name="myform" method="get">  
                <input name="contenta" type="text" value="回车提交" /></br>
                <input type="text" style="display:none">  
             </form>  
        </body>  
    </html>  

    [2]禁用form的onsubmit事件:

    <html>  
        <head>  
            <title>页面中只有一个input元素时默认提交表单</title>  
        </head>  
        <body>  
             <form onsubmit="return false;"action="XXX" name="myform" method="get">  
                <input name="contenta" type="text" value="Enter To Submit" /></br>  
             </form>  
        </body>  
    </html> 
    <script type="text/javascript">
    function update() {
      document.forms[0].action="${contextPath}UpdateAction.action";
      document.forms[0].submit();
    }
    </script>
  • 相关阅读:
    UE4 多人模式
    UE4 r.ScreenPercentage 150 导致的画面只有丢失
    UE4 3D Widget渲染优先级最高
    UE4 VR中血条的做法 3d widget
    UE4 源码bug 蓝图节点CreateSession导致的崩溃
    UE4 小技巧
    ue4(转载) 在VR中的按钮 Button In VR
    ue4 可点击座舱实现 Clickable cockpit
    两种排序方法(选择排序和冒泡排序)
    特殊的Josn格式
  • 原文地址:https://www.cnblogs.com/xinaixia/p/5132508.html
Copyright © 2011-2022 走看看