JQuery实例入门(添加鼠标事件)
2008-11-04 16:02
656 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<script type="text/javascript" src="js/jquery-1[1].2.6.min.js"></script>
<style type="text/css">
.over {
background:Red; /*这个将是鼠标高亮行的背景色*/
}
.color{
background:Green;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$("#user").mouseover(function(){
$(this).removeClass("color").addClass("over");
$(this).attr("height","100px");
})
.mouseout(function(){
$(this).removeClass("over").addClass("color");
});
})
</script>
</head>
<body>
<div id="user" class="color">鼠标移动过来</div>
</body>
</html>
http://wiki.jquery.org.cn/doku.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<script type="text/javascript" src="js/jquery-1[1].2.6.min.js"></script>
<style type="text/css">
.over {
background:Red; /*这个将是鼠标高亮行的背景色*/
}
.color{
background:Green;
}
</style>
<script type="text/javascript">
/*
此教程目的是让那些新手通过实际应用,对jquery有一个初步了解。
传说中的ready
$(document).ready() 作用就是 在页面加载完成之后执行 封装在里面的js.
你可以在一个页面中使用任意多个$(document).ready事件
*/
/*----------------传说中的ready-------------------*/
$(document).ready(function() {
/*------------------end-----------------*/
/*jQuery的链式操作
正常情况下应该写成
$("#user").mouseover(function(){
$(this).addClass("over");
});
$("#user").mouseout(function(){
$(this).removeClass("over");
});
但是我们现在写成 $("#user").mouseover().mouseout()这种形式;
因为 在jQuery中,执行完mouseover或者mouseout等方法之后,都会返回当前的对象,所以可以进行链式操作
*/
/*----------------链式操作例子-------------------*/
$("#user").mouseover(function(){
$(this).removeClass("color").addClass("over");
$(this).attr("height","100px");
})
.mouseout(function(){
$(this).removeClass("over").addClass("color");
});
/*-----------------end-----------------*/
})
</script>
</head>
<body>
<div id="user" class="color">鼠标移动过来</div>
</body>
</html>
去掉注释,清晰一些
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<script type="text/javascript" src="js/jquery-1[1].2.6.min.js"></script>
<style type="text/css">
.over {
background:Red; /*这个将是鼠标高亮行的背景色*/
}
.color{
background:Green;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$("#user").mouseover(function(){
$(this).removeClass("color").addClass("over");
$(this).attr("height","100px");
})
.mouseout(function(){
$(this).removeClass("over").addClass("color");
});
})
</script>
</head>
<body>
<div id="user" class="color">鼠标移动过来</div>
</body>
</html>
http://wiki.jquery.org.cn/doku.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<script type="text/javascript" src="js/jquery-1[1].2.6.min.js"></script>
<style type="text/css">
.over {
background:Red; /*这个将是鼠标高亮行的背景色*/
}
.color{
background:Green;
}
</style>
<script type="text/javascript">
/*
此教程目的是让那些新手通过实际应用,对jquery有一个初步了解。
传说中的ready
$(document).ready() 作用就是 在页面加载完成之后执行 封装在里面的js.
你可以在一个页面中使用任意多个$(document).ready事件
*/
/*----------------传说中的ready-------------------*/
$(document).ready(function() {
/*------------------end-----------------*/
/*jQuery的链式操作
正常情况下应该写成
$("#user").mouseover(function(){
$(this).addClass("over");
});
$("#user").mouseout(function(){
$(this).removeClass("over");
});
但是我们现在写成 $("#user").mouseover().mouseout()这种形式;
因为 在jQuery中,执行完mouseover或者mouseout等方法之后,都会返回当前的对象,所以可以进行链式操作
*/
/*----------------链式操作例子-------------------*/
$("#user").mouseover(function(){
$(this).removeClass("color").addClass("over");
$(this).attr("height","100px");
})
.mouseout(function(){
$(this).removeClass("over").addClass("color");
});
/*-----------------end-----------------*/
})
</script>
</head>
<body>
<div id="user" class="color">鼠标移动过来</div>
</body>
</html>
去掉注释,清晰一些
相关文章推荐
- JQuery实例入门(添加鼠标事件)
- 以申购单为实例,讲解Jquery动态删减行,新增行添加鼠标事件,子窗口与父窗口传值,自动计算金额,及输入值的验证,前台数据批量提交到后台action
- jquery 添加鼠标滑动事件
- jquery 给图片添加遮罩 响应鼠标事件出现提示
- jquery 添加<table> 再添加鼠标点击事件
- jquery.动态添加标签和事件实现实例
- jQuery添加options点击事件并传值实例代码
- opengl入门实例(4)-鼠标事件
- jQuery实现为动态添加的元素绑定事件实例分析
- 用JQuery给图片添加鼠标移入移出事件
- 史上最全的CSS hack方式一览 jQuery 图片轮播的代码分离 JQuery中的动画 C#中Trim()、TrimStart()、TrimEnd()的用法 marquee 标签的使用详情 js鼠标事件 js添加遮罩层 页面上通过地址栏传值时出现乱码的两种解决方法 ref和out的区别在c#中 总结
- jquery append()方法添加的标签为什么不能添加事件?
- Xamarin.Android 入门实例(4)之实现对 SQLLite 进行添加/修改/删除/查询操作
- VB6.0 IDE添加鼠标滑轮事件
- jQuery移动页面开发中的触摸事件与虚拟鼠标事件简介
- jquery给动态添加的元素绑定事件
- jQuery事件之鼠标事件
- Jquery动态添加节点,绑定事件失效的解决方法
- jQuery1.6.1下event鼠标事件有BUG,升级到1.7.1可以解决问题。