zoukankan      html  css  js  c++  java
  • jquery 例子

    引用:http://hi.baidu.com/coolcat_police/blog/item/fb7b7f458ebde12ccffca3bb.html


    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">

    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
            <style>
                .red{color:red;}
                .green{color:green;}
            </style>
            <script type="text/javascript" src="jquery-1.2.6.js"></script> 
            <script language="javascript">
                $(function(){
                    //为所有a标签添加red样式
                    $("a").addClass("red");

                    //为所有a标签添加onclick事件
                    $("a").click(function(){
                        alert("你点击了超链接");
                    });   
                    
                    //为id为bb的元素添加onclick事件
                    $("#removeRedClass").click(function(){
                        //为所有a标签删除red样式
                        $("a").removeClass("red");
                    });
                    
                    //为id为orderedlist的li元素添加red样式
                    $("#orderedlist li").addClass("red");
                    
                    //迭代id为orderedlist的li元素
                    $("#orderedlist li").each(function(i){
                        $(this).html("标签"+i);
                    });
                    
                    //为id为orderedlist的最后li元素添加hover事件
                    $("#orderedlist li:last").hover(function(){$(this).addClass("green");}, 
                    function(){$(this).removeClass("green");});
                    
                    //为id为testAjax的按钮添加Ajax功能
                    $("#testAjax").click(function(){
                        $.ajax({
                            url:'testAjax.xml',
                            type:'post',
                            dataType:'text', //xml,json,text
                            timeout:5000,
                            error:function(){
                                alert('找不到url资源!');
                            },
                            success:function(xml){
                                alert(xml);
                            }
                        });
                    });
                });
            </script>
        </head>
        <body>
            <a href="#">点击触发超链接的onclick事件</a><br/>
            <button id="removeRedClass">点击删除a标签的red样式</button><br/>
    <ol id="orderedlist">
                <li>First element</li>
                <li>Second element</li>
                <li>Third element</li>
    </ol><br/>
            <button id="testAjax">ajax button</button>
        </body>
    </html>

  • 相关阅读:
    Cocos2dx-lua开发之c++绑定到lua
    SCOPE_IDENTITY和@@IDENTITY[转]
    c#List结合IEqualityComparer求交集
    K:java中正则表达式的使用说明及其举例
    K:常见的正则表达式
    K:正则表达式之基础简介
    Q:javax.comm 2.0 windows下Eclipse的配置
    Q:同时安装了python2和python3的电脑下pip的使用
    K:java 断言 assert 初步使用:断言开启、断言使用
    请描述一下 cookies,sessionStorage 和 localStorage 的区别
  • 原文地址:https://www.cnblogs.com/sode/p/2649412.html
Copyright © 2011-2022 走看看