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>

  • 相关阅读:
    基于Memcached的tomcat集群session共享所用的jar及多个tomcat各种序列化策略配置
    response.getWriter().write()和 response.getWriter().print()的区别
    response.getWriter().write()与out.print()的区别
    跳转到页面后加载一个请求的方法
    【遍历集合】Java遍历List,Map,Vector,Set的几种方法
    Java中通过方法创建一个http连接并请求(服务器间进行通信)
    【tomcat】手动部署动态JavaWeb项目到tomcat
    【Eclipse】Eclipse中修改项目的映射名称与端口
    使用Cookie进行会话管理
    操作系统内核框架图整理
  • 原文地址:https://www.cnblogs.com/sode/p/2649412.html
Copyright © 2011-2022 走看看