請教關于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. html5 - ElementUI table中el-table-column怎么設置百分比顯示。2. python - 使用readlines()方法讀取文件內容后,再用for循環遍歷文件與變量匹配時出現疑難?3. 對mysql某個字段監控的功能4. css3 - less或者scss 顏色計算的知識應該怎么學?或者在哪里學?5. 注冊賬戶文字不能左右分離6. javascript - table列過多,有什么插件可以提供列排序和選擇顯示列的功能7. css - 網頁div區塊 像蘋果一樣可左右滑動 手機與電腦8. javascript - 數組的過濾和渲染9. html - vue項目中用到了elementUI問題10. JavaScript事件
