zoukankan      html  css  js  c++  java
  • onsubmit事件、事件传播判定函数stoppropagetion、事件使用2种方式

    <body>
    <form action=""id="form1">
        <input type="text" name="username">
        <input type="submit" value="提交  ">
    
    </form>
        <script>
            var ele=document.getElementById("form1");//时间绑定的主要方法
            ele.onsubmit=function (e) {//onsubmit事件,点击就会触发此事件执行此函数
                //e(event)是事件对象,会封装信息,比如按了回车键,这个键的信息就封装存放在e中
                //alert(1234)
                //console.log("hello")
                //return false//不写return false 默认向后端发送文本框输入内容,
                // 写了return false 就停止不发到后端,文本框无法刷新
                e.preventDefault()//阻止默认事件和return false 相同用法
            }
        </script>
    <body>
    <!--事件传播:1和2的公共部分无法确定是谁的,通过stoppropagation限定1就是1的不是二的,不允许事件扩散-->
     1<div class="outer" onclick="fun2()">
        <div class="inner" ></div>
    </div>
        <script>
          2  var ele=document.getElementsByClassName("inner")[0];
            ele.onclick=function (e) {
                  alert("i am inner");
                e.stopPropagation();//通过他判定小的就是小的,不算大的
    
            }
    
         1   function fun2() {
                alert("i am outer")
            }
        </script>
  • 相关阅读:
    Leetcode: Surrounded Regions
    Leetcode: 3Sum Closest
    Leetcode: 3Sum
    Leetcode: Wildcard Matching
    Leetcode: Edit Distance
    Leetcode: Best Time to Buy and Sell Stock III
    Leetcode: Combination Sum II
    Leetcode: Next Permutation
    Leetcode: Merge Intervals
    Leetcode: Minimum Window Substring
  • 原文地址:https://www.cnblogs.com/wfl9310/p/9203661.html
Copyright © 2011-2022 走看看