div无法触发blur事件解决的方法
生活随笔
收集整理的這篇文章主要介紹了
div无法触发blur事件解决的方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
默認情況下div無法獲取焦點,無法觸發focus與blur事件,推測span,a等標簽也無法觸發焦點事件(input:button。及button標簽能夠觸發)
怎樣使div觸發blur事件:能夠給div加上tabindex屬性
在線演示:http://sandbox.runjs.cn/show/e0bvfcag
源代碼:
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Document</title><style>.box{width: 200px;height: 200px;background-color: #3295F2;}</style><script type="text/javascript" src="http://sandbox.runjs.cn/uploads/rs/294/c4c2o6mh/jquery.js"></script> </head> <body><input type="text" /><input type="button" value="測試" class="but"/><button>kkk</button><div class="box" tabindex="1"></div><script>$('.box').focus(function(){alert('div focus');});$('.box').blur(function(){alert('div blur');});$('.but').focus(function(){alert('but');});$('.but').blur(function(){alert('but');});$('button').focus(function(){alert('but');});$('button').blur(function(){alert('but');});</script> </body> </html>demo: ?http://www.w3school.com.cn/tiy/t.asp?
f=html_standard_tabindex
轉載于:https://www.cnblogs.com/mengfanrong/p/5190108.html
總結
以上是生活随笔為你收集整理的div无法触发blur事件解决的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 快捷工具,如何清理不需要的引用
- 下一篇: oracle数据库启动