现在的位置: 首页 > 综合 > 正文

JQuery Tutorial

2013年11月13日 ⁄ 综合 ⁄ 共 2802字 ⁄ 字号 评论关闭

jQuery JavaScript Library v1.4.2

jquery.js

1.对于div中的id 或class的引用

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

    $(document).ready(function () {

        $('.yes').hide();
        //for id
        //$('#yes').hide();
    })
    
</script>
</head>
<body>
<div class="yes" id="yes" >yes</div>
<div>text1</div>
<div>text2</div>
</body>
</html>

2.button的单击事件 & toggle()

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

    $(document).ready(function () {

        $('#button').click(function () {
            $('#zxl').toggle();
            $('#button').val('zbutton');
        });
    })
    
</script>
</head>
<body>
<input type="submit" id="button" />
<div id="zxl" >type some text</div>

</body>
</html>

3.jquery 中的css

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

    $(document).ready(function () {

        $('ul li').each(function (e) {
            if (e != 2) {
                $(this).css('background', 'red');
            }
            $('li').eq(2).css('background', 'green');
            $('li').has('b').css('background', 'blue');
            $(this).append(e);
        });


    })
    
</script>
</head>
<body>

<h1>zzz</h1>
<ul>
    <li>this is an item</li>
    <li>this is an item</li>
    <li>this is an item</li>
    <li><b>this</b> is an item</li>
    <li>this is an item</li>
    <li>this is an item</li>
    <li>this is an item</li>
    <li>this is an item</li>
    <li>this is an item</li>
</ul>

</body>
</html>

4.jquery  fadeIn/fadeOut  Effects效果

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

    $(document).ready(function () {
//        SHOW效果
//        $('h1').hide();
//        $('#button').click(function () {
//            $('h1').show();
//        });

//        slidedown效果
//        $('h1').hide();
//        $('#button').click(function () {
//            $('h1').slideDown(3000);
//        });

//        slideUp效果
//        $('#button').click(function () {
//            $('h1').slideUp(3000);
//        });

//      fadeout效果
        $('#button').click(function () {
            $('h1').fadeOut(3000);
        });


    })
    
</script>
</head>
<body>

<h1>zzz</h1>
<ul>
    <li><b>this</b> is an item</li>
    <li>this is an item</li>
    <li>this is an item2</li>
    <li>this is an item</li>
    <li>this is an item</li>
</ul>
<input id="button" type="submit" />

</body>
</html>

5.jquery Custom Functions

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

    $(document).ready(function () {

//        //无参数
//        $.fn.YourName = function () {
//            alert('zxl');
//        }
//        //带参数
//        $.fn.zxl = function (str) {
//            alert(str);
//        }

//        $('#button').click(function () {
//            $(this).YourName();
//            $(this).zxl('hello zxl');
//        });
///////////////////////////////////////////////////////////////
//        //无参数
//        $.fn.customThing = function () {
//            return $(this).css('background','green').fadeOut(3000);
//        }

//        $('#button').click(function () {
//            $('h1').customThing();
//        });

        //有参数
        $.fn.customThing = function (color) {
            return $(this).css('background', color).fadeOut(3000);
        }

        $('#button').click(function () {
            $('h1').customThing('blue');
        });


    })
    
</script>
</head>
<body>

<h1>zzz</h1>
<ul>
    <li><b>this</b> is an item</li>
    <li>this is an item</li>
    <li>this is an item2</li>
    <li>this is an item</li>
    <li>this is an item</li>
</ul>
<input id="button" type="submit" />

</body>
</html>

抱歉!评论已关闭.