jQuery event.isImmediatePropagationStopped()方法用法示例

2021年3月12日13:11:14 发表评论 840 次浏览

isImmediatePropagationStopped()方法在jQuery中用于检查此方法是否呼吁事件or不。如果它被调用, 它将是"true"要不然"false".

语法如下:

$(selector).isImmediatePropagationStopped()

参数:此方法仅接受一个参数作为选择器, 用于选择元素。

返回值:如果event.stopImmediatePropagation()被调用, 则此方法返回true;否则, 将返回false。

示例1:

<!DOCTYPE html>
< html >
  
< head >
     < script src =
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" >
   </ script >
     < style >
         body {
             width: 60%;
             height: 40%;
             padding: 20px;
             border: 2px solid green;
         }
          
         div {
             padding: 5px;
             display: block;
             background-color: lightgrey;
             font-size: 20px;
         }
     </ style >
    
   < script >
       $(document).ready(function() {
          $("div").click(function(event) {
             event.stopImmediatePropagation();
             alert(
             "Was event.stopImmediatePropagation() called: "
              + event.isImmediatePropagationStopped());
          });
      });
   </ script >
</ head >
  
< body >
  
     < div >Welcome to lsbin..!</ div >
  
</ body >
  
</ html >

输出如下:

在单击div元素之前:

jQuery | event.isImmediatePropagationStopped()方法1

单击div元素后:

jQuery | event.isImmediatePropagationStopped()方法2

示例2:

<!DOCTYPE html>
< html >
  
< head >
     < script src =
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" >
   </ script >
     < style >
         body {
             width: 60%;
             height: 40%;
             padding: 20px;
             border: 2px solid green;
         }
          
         div {
             padding: 5px;
             display: block;
             background-color: lightgrey;
             font-size: 20px;
         }
     </ style >
     
   < script >
     $(document).ready(function() {
      $("div").click(function(event) {
       alert(
       "Value of event.stopImmediatePropagation() called: "
         + event.isImmediatePropagationStopped());
      });
   });
   </ script >
</ head >
  
< body >
  
     < div >Welcome to lsbin..!</ div >
  
</ body >
  
</ html >

输出如下:

在点击" div"元素之前:

jQuery | event.isImmediatePropagationStopped()方法3

单击" div"元素后:

jQuery | event.isImmediatePropagationStopped()方法4

木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: