jQuery 的第一个例子

通过这个例子可以对jQuery的使用有个基本的认识,jQuery的事件句柄、选择器、基本语法结构,你可以复制这些代码运行感受一下。

在做第一个例子之前,你需要先到jQuery 1.3 正式版 下载 jQuery库,他是一个js的文件非常的小巧只有那么几十KB,然后就是把这个文件Copy到你的项目,用Script附加这个文件就可以了。

Code
Code

<!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 runat="server">
    
<title></title>

    
<script src="jquery.js" type="text/javascript"></script>

    
<style type="text/css">
        .red
        
{
            background-color
: Red;
        
}
        .green
        
{
            background-color
: Green;
        
}
        .blue
        
{
         background-color
: Blue;
        
}
    
</style>

    
<script type="text/javascript">

        $(document).ready(
        
function() {
            $(
"div").addClass("blue");
            
//$("#olID>li").addClass("green");

            $(
"#olID>li").hover(
            
function() {
                $(
this).addClass("red")
            },
            
function() {
                $(
this).removeClass("red")
            });

            $(
"#olID>li:last").hover(
            
function() {
                $(
this).addClass("green");

            },
            
function() {
                $(
this).removeClass("green");

            })
        })
        
    
</script>

</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
<ol id="olID">
            
<li>Terry.Feng.C</li>
            
<li>冯瑞涛</li>
            
<li>f@gmail.com</li>
        
</ol>
    
</div>
    
</form>
</body>
</html>
冯瑞涛
原文地址:https://www.cnblogs.com/finehappy/p/1377769.html