作者Rplus (R+) (9527)
看板Ajax
标题[问题][jQ] bind / unbind
时间Fri Nov 2 23:23:53 2012
view on-line
http://jsbin.com/acawor/3/edit
DOM:
---------------------
div
#SelectTime
div
#SelectData
div 1111
div 2222
div 3333
---------------------
理想动作:
1. click '
#SelectTime' 时,
#SelectData 开/合
2. click '
#SelectData>div' 时,
#SelectData 合上
& 当前点击的 div addClass 'focus'
3. click 'div.focus' 时, 不动作 (意即 第二点的 click 需无效化)
手拙写了js
但是unbind後有问题发生,
想请教该如何修正?
感谢!
---------------
$(function() {
var _selectData = $('
#SelectData');
function toggleData() {
_selectData.slideToggle(250);
}
$('
#SelectTime').bind('click',toggleData);
$('
#SelectData>div:not(.focus)').click(function(){
_selectData.slideUp(250);
$(this).siblings().removeClass('focus').end().addClass('focus');
$('
#SelectData>div').bind('click');
$('
#SelectData>div.focus').unbind('click');
});
});
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.240.213.71
2F:→ Rplus:效果正我我预想的一样!!! 先感谢!!! (我再慢慢研究一下code 11/03 00:03
3F:→ Rplus:不过为什麽var $this = $(this);写在if後面就不能动了呀? 11/03 00:07
4F:→ Rplus:啊... 当我没问XDD 11/03 00:07
5F:→ terlin10:Raven... 11/03 09:19
6F:→ Rplus:嗨~ 11/03 18:46