zoukankan      html  css  js  c++  java
  • 解决前台JS弹框Alert点击确定页面会刷新

    问题描述

    点击alert弹出的对话框中的确定按钮之后页面自动刷新,怎样防止不刷新?

    示例:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script src="jquery-3.5.1/jquery-3.5.1.js"></script>
        <title></title>
        <script>
            function send() {
                var name = $('#name').val();
                if (name == '') {
                    alert('name不能为空')
                    return false;
                }
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <input id="name" type="text" />
                <button onclick="send();" type="button">按钮</button>
            </div>
        </form>
    </body>
    </html>

    有人说:在alert 后面 写一个 return false 页面就不会刷新了;还有人说:正常情况 alert 之后页面是不会刷新的,应该是做了刷新的动作,然而并没有什么卵用。

    点击按钮的时候,执行send()方法,弹出alert提示框,然后页面就自动刷新了。原因是button缺少type类型,加上 type=“button” 就好了,本以为button本身就是按钮,不需要再声明它的类型了,这才导致了这次的问题。

    原文链接:https://blog.csdn.net/bxj19890514/article/details/82771380

  • 相关阅读:
    课后作业一
    软工假期预习作业
    Spark2.0自定义累加器
    JAVA hashmap知识整理
    Spark 累加器
    RDD与DataFrame的转换
    Scala笔记整理
    Spark RDD
    Hbase的flush机制
    Spring源码-ImportSelector实现分析
  • 原文地址:https://www.cnblogs.com/zhaoyl9/p/14267027.html
Copyright © 2011-2022 走看看