請(qǐng)教關(guān)于jquery阻止冒泡的問題?
問題描述
如圖,我有一個(gè)彈窗想點(diǎn)擊除輪播區(qū)域外的地方關(guān)閉彈窗,點(diǎn)擊切換按鈕實(shí)現(xiàn)切換圖片

代碼如下
$('.cut-model').bind('click',function(e){ $(this).hide();//點(diǎn)擊空白區(qū)域關(guān)閉彈窗})$('.round').bind('click',function(e){ e.stopPropagation();//點(diǎn)擊切換按鈕阻止冒泡})
然而。。。。并沒有成功,點(diǎn)擊切換按鈕時(shí)彈窗仍然關(guān)閉,請(qǐng)教各位大神是什么原因,我寫的不對(duì)嗎?謝謝
問題解答
回答1:請(qǐng)教關(guān)于jquery阻止冒泡的問題?-PHP中文網(wǎng)問答-請(qǐng)教關(guān)于jquery阻止冒泡的問題?-PHP中文網(wǎng)問答
圍觀一下哦,學(xué)習(xí)一下。
回答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("不關(guān)閉overlay");event.stopPropagation();//阻止冒泡到.over-lay }); $(".over-lay").on("click",function(event){console.log("關(guān)閉overlay");$(this).addClass("hide"); });}); </script></head><body><div> <div class="back-button">后退</div> <div></div> <div class="forward-button">前進(jìn)</div></div></body></html>
相關(guān)文章:
1. javascript - sublime快鍵鍵問題2. javascript - immutable配合react提升性能?3. css - 寫頁面遇到個(gè)布局問題,求大佬們幫解答,在線等,急!~4. javascript - nodejs關(guān)于進(jìn)程間發(fā)送句柄的一點(diǎn)疑問5. Apache 已經(jīng)把網(wǎng)站根目錄的改為allow from all了,但是服務(wù)器還是不能訪問?6. 實(shí)現(xiàn)bing搜索工具urlAPI提交7. 配置Apache時(shí),添加對(duì)PHP的支持時(shí)語法錯(cuò)誤8. vue.js - Vue 如何像Angular.js watch 一樣監(jiān)聽數(shù)據(jù)變化9. javascript - 移動(dòng)端上不能實(shí)現(xiàn)拖拽布局嗎?10. phpstudy8.1支持win11系統(tǒng)嗎?

網(wǎng)公網(wǎng)安備