Ajax 板


LINE

其实我完全没有这个需求...不过无聊就练习一下: // jquery 1.2.6 引进了的自订事件的语法 // 我们要 overwrite blur 事件 $.event.special.blur = { //当事件被注册的时候,会先呼叫这个 function //此 function 中的 this 就是被注册事件的 element setup: function() { // 先判断此 element 是不是本来就可以 bind blur // 这里我直接比对 tagName 是不是 input/select 之类的 var tag_name = this.tagName; if(tag_name == 'INPUT' || tag_name == 'SELECT' || tag_name == 'TEXTAREA' || tag_name =='BUTTON' || tag_name == 'LABEL') { return false; //回传 false 表示用预设的行为 } //因为 js scope 的问题,先把 this 存在另一个变数中 var that = $(this); // 为此 element 增加一个用来 proxy 事件的 input if(!this.proxy_input){ //如果已经有这个 proxy input 了...就不用再生一次了 this.proxy_input = $('<input type="text" />'). // 生出来 addClass('proxy_input'). // 加上 class name insertAfter(this). // 放到原本的 element 後面 focus(function() { that.focus(); }). // proxy focus event blur( function() { that.blur(); }). // proxy blur event css({ top: that.offset().top, // 将它的位置设成和原来一样 left: that.offset().left, width: that.width(), height: that.height() }); } return true; }, //当事件被取消的时候,会先呼叫这个 function teardown: function() { //同样先判断是不是原本就可以 bind blur 的 element var tag_name = this.tagName; if(tag_name == 'INPUT' || tag_name == 'SELECT' || tag_name == 'TEXTAREA' || tag_name =='BUTTON' || tag_name == 'LABEL') { return false; } // 清掉 proxy input this.proxy_input.remove(); this.proxy_input = null; return true; } } 这样 overwrite blur 事件後,就可以直接对 div bind blur 了: $('div.test').blur(function(){ console.log('blur div.test') }); 要特别说明的是,做出来的 proxy_input 会放在原来的 element 的上方,目的是要 让使用者在 click 原来的 element 时,其实却 click 到了我们的 proxy_input 为了让使用者看不到我们的 proxy_input ,要加上特别的 style input.proxy_input { position: absolute; filter:alpha(opacity=0); opacity: 0; -moz-opacity:0; } 以上的 code 只在 firefox 中测试过.. --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.135.70.236
1F:→ TonyQ:soga , 原来是透明後完全盖住 , 这倒是没想到. GJ :p 09/19 09:48
2F:→ TonyQ:不晓得这样对原本元素的hover/click等事件还会不会存在:p 09/19 09:59
3F:→ TonyQ:这有测试的价值 , 找个时间来测一下... 09/19 09:59
4F:→ contagious:查了一下..其实好像只要加上 tabindex 就可以 focus 了 09/19 12:46
5F:→ contagious:不过初步测试 ff/ie 都可以..但是 safari 不行... 09/19 12:47
6F:→ contagious:http://0rz.tw/314OX 09/19 13:19
7F:→ TonyQ:soga .. 感恩这情报. 09/19 13:33
8F:→ TonyQ:找时间测试一下 , 很感谢你对这问题的不吝分享. :p 09/19 13:35







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:e-shopping站内搜寻

TOP