請教關于jquery阻止冒泡的問題?
問題描述
如圖,我有一個彈窗想點擊除輪播區域外的地方關閉彈窗,點擊切換按鈕實現切換圖片
代碼如下
$('.cut-model').bind('click',function(e){ $(this).hide();//點擊空白區域關閉彈窗})$('.round').bind('click',function(e){ e.stopPropagation();//點擊切換按鈕阻止冒泡})
然而。。。。并沒有成功,點擊切換按鈕時彈窗仍然關閉,請教各位大神是什么原因,我寫的不對嗎?謝謝
問題解答
回答1:請教關于jquery阻止冒泡的問題?-PHP中文網問答-請教關于jquery阻止冒泡的問題?-PHP中文網問答
圍觀一下哦,學習一下。
回答2:<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>Title</title> <script type="text/javascript" src="jquery.min.js"></script> <style>.over-lay{ width: 300px; height: 300px; position: absolute; left:50px; top:50px; background-color: rgba(235,235,235,0.5);}.over-lay.hide{ display: none;}.content{ background-color: green; width: calc(100% - 60px); height: calc(100% - 0px); border-radius: 10px; position: absolute; left: 30px; top: 0px;}.back-button,.forward-button{ width: 30px; height: 30px; position: absolute; top:calc(50% - 15px); left:0px; background-color: red; font-size: 12px;}.forward-button{ right:0px; left:auto;} </style> <script>$(function(){ $(".over-lay").on("click",".back-button,.forward-button",function(event){ console.log("不關閉overlay");event.stopPropagation();//阻止冒泡到.over-lay }); $(".over-lay").on("click",function(event){console.log("關閉overlay");$(this).addClass("hide"); });}); </script></head><body><div> <div class="back-button">后退</div> <div></div> <div class="forward-button">前進</div></div></body></html>
相關文章:
1. javascript - node.js promise沒用2. golang - 用IDE看docker源碼時的小問題3. yii2中restful配置好后在nginx下報404錯誤4. 算法 - python 給定一個正整數a和一個包含任意個正整數的 列表 b,求所有<=a 的加法組合5. android 如何實現如圖中的鍵盤上的公式及edittext的內容展示呢6. java - 我在用Struts2上傳文件時,報以下錯誤怎么回事?7. c++ - 如何正確的使用QWebEngineView?8. PHP注冊功能9. php - TP5的登錄驗證問題10. php - 注冊驗證郵箱失效后操作問題
