1
2
3
4
5
6
7
|
Behaviour.register({
'#example li': function(e){
e.onclick = function(){
this.parentNode.removeChild(this);
}
}
});
|
1
2
3
4
5
|
$('#example li').bind('click',function(){
this.parentNode.removeChild(this);
});
第二个例子是为不同的元素注册不同的事件:
|
1
2
3
4
5
6
7
8
9
10
11
12
|
Behaviour.register({
'b.someclass' : function(e){
e.onclick = function(){
alert(this.innerHTML);
}
},
'#someid u' : function(e){
e.onmouseover = function(){
this.innerHTML = "BLAH!";
}
}
});
|
1
2
3
4
5
6
|
$('b.someclass').bind('click',function(){
alert(this.innerHTML);
});
$('#someid u').bind('mouseover',function(){
this.innerHTML = 'BLAH!';
});
|
1
2
3
4
5
6
7
8
9
10
11
12
|
Behaviour.register({
'#foo ol li': function(a) {
a.title = "List Items!";
a.onclick = function(){ alert('Hello!'); };
},
'#foo ol li.tmp': function(a) {
a.style.color = 'white';
},
'#foo ol li.tmp .foo': function(a) {
a.style.background = 'red';
}
});
|
1
2
3
4
5
6
7
|
$('#foo ol li')
.set('title','List Items!')
.bind('click',function(){ alert('Hello!'); })
.select('.tmp')
.style('color','white')
.select('.foo')
.style('background','red');
|
1
2
3
4
5
6
7
8
9
10
|
//1.4.2
$("table").delegate("td", "hover", function(){
$(this).toggleClass("hover");
});
//1.3.2
$("table").each(function(){
$("td", this).live("hover", function(){
$(this).toggleClass("hover");
});
});
|
1
|
$("p")
|
元素
1
|
$("#test")
|
1
|
$(".test")
|
1
|
$("p").click();
|
1
2
3
|
$("p").click(function(){
// 动作触发后执行的代码!!
});
|
元素上触发时,隐藏当前的
元素:
1
2
3
|
$("p").click(function(){
$(this).hide();
});
|
1
2
3
|
$("p").dblclick(function(){
$(this).hide();
});
|
1
2
3
|
$("#p1").mouseenter(function(){
alert("You entered p1!");
});
|
1
2
3
|
$("#p1").mouseleave(function(){
alert("Bye! You now leave p1!");
});
|
1
2
3
|
$("#p1").mousedown(function(){
alert("Mouse down over p1!");
});
|
1
2
3
|
$("#p1").mouseup(function(){
alert("Mouse up over p1!");
});
|
1
2
3
4
5
6
|
$("#p1").hover(function(){
alert("You entered p1!");
},
function(){
alert("Bye! You now leave p1!");
});
|
1
2
3
|
$("input").focus(function(){
$(this).css("background-color","#cccccc");
});
|
1
2
3
|
$("input").blur(function(){
$(this).css("background-color","#ffffff");
});
|