javascript or jquery

/==================================入门实例==============================================

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'demo1.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
 <script type="text/javascript" src="js/jquery-1.6.2.js"></script>
   <script type="text/javascript">
    $(this).ready(
     function(){
      $("#demo").css("color","red");
    });  
   
   </script>
  </head>
 
  <body>
     <A herf="#" id="demo" >观察我的变化</A>
  </body>
</html>

============================================表格奇 偶变色======================

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme() + "://"
   + request.getServerName() + ":" + request.getServerPort()
   + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <base href="<%=basePath%>">

  <title>My JSP 'demo1.jsp' starting page</title>

  <meta http-equiv="pragma" content="no-cache">
  <meta http-equiv="cache-control" content="no-cache">
  <meta http-equiv="expires" content="0">
  <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  <meta http-equiv="description" content="This is my page">
  <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
  <script type="text/javascript" src="js/jquery-1.6.2.js">
</script>

<script type="text/javascript">

//用DOM方式来让表格奇偶变色

//window.οnlοad=function(){

//var myTable=document.getElementById("mytable");
//var myTbody=myTable.getElementsByTagName("tbody");
//var trs=myTbody[0].getElementsByTagName("tr");
//for(var i=0;i<trs.length;i++){
//if(i%2==0){
//trs[i].style.backgroundColor="red";
//}else{
//trs[i].style.backgroundColor="blue";
//}
//}

//}

/**
 *
 *用Jquery来是表格变色
 */

$(this).ready(function(){
 //:even过滤出为偶数的行
 $("#mytable tr:even").css("background","yellow");
 //:odd过滤出为奇数行的
 $("#mytable tr:odd").css("background","gray");
 }
);
 

</script>
 </head>

 <body>
  <table id="mytable" border="1">
   <tbody>
    <tr>
     <td>
      11111111
     </td>
     <td>
      11111111
     </td>
     <td>
      11111111
     </td>
    </tr>
    <tr>
     <td>
      22222222
     </td>
     <td>
      22222222
     </td>
     <td>
      22222222
     </td>
    </tr>
    <tr>
     <td>
      33333333
     </td>
     <td>
      33333333
     </td>
     <td>
      33333333
     </td>
    </tr>
    <tr>
     <td>
      4444444
     </td>
     <td>
      4444444
     </td>
     <td>
      4444444
     </td>
    </tr>
    <tr>
     <td>
      55555555
     </td>
     <td>
      55555555
     </td>
     <td>
      55555555
     </td>
    </tr>
    <tr>
     <td>
      666666666
     </td>
     <td>
      666666666
     </td>
     <td>
      666666666
     </td>
    </tr>
   </tbody>
  </table>
 </body>
</html>

====================================复选框的选中========================================

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'demo1.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
 <script type="text/javascript" src="js/jquery-1.6.2.js"></script>
   <script type="text/javascript">
    //window.οnlοad=function(){
     //document.getElementById("btn").οnclick=
      //function(){
       //var count=0;
       //var chks=document.getElementsByName("boxs");
       //for(var i=0;i<chks.length;i++){
        //if(chks[i].checked){
         //count++;
        //}
      // }
       //alert(count);
      
     // } 
    //}
    
    $(function(){
     $("#btn").click(function(){
      alert($("input:checked").length);
     });
     
     
    });
    
   </script>
  </head>
 
  <body>
     <input type="checkbox" name="boxs" checked="checked"/><br/>
     <input type="checkbox" name="boxs"/><br/>
     <input type="checkbox" name="boxs"/><br/>
     <input type="checkbox" name="boxs" checked="checked"/><br/>
     <input type="checkbox" name="boxs"/><br/>
     <br/>
     <input type="button" id="btn" value="单击我查看选中的数目"/>
  </body>
</html>

==============================Jquery 属性======================

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'demo1.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
 <script type="text/javascript" src="js/jquery-1.6.2.js"></script>
   <script type="text/javascript">
    $(function(){
     var $p=$("p");
     var $li=$("ul li:eq(2)");
     alert($p.attr("title")+"  "+$p.text());
    alert($li.attr("title")+"  "+$li.text());    
    }); 
   
   
   </script>
  </head>
 
  <body>
      <p title="hello  world">小王梅  我爱你</p>
      <ul>
       <li title="1">你好</li>
       <li title="2">你很好</li>
       <li title="3">你非常好</li>
       <li title="4">你帅</li>
       <li title="5">你很帅</li>
       <li title="6">你非常帅</li>
      </ul>
  </body>
</html>

===========================html页面中添加元素=========================

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'demo1.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
 <script type="text/javascript" src="js/jquery-1.6.2.js"></script>
   <script type="text/javascript">
     //---使用javascript来添加元素
   /**  
    function addItems(){
     document.getElementById("div1").innerHTML="";
     var num=parseInt(document.getElementById("num").value);
     for(var i=0;i<num;i++){
      var input=document.createElement("input");
       input.type="text";
       input.setAttribute("name","items");
      var br=document.createElement("br"); 
       document.getElementById("div1").appendChild(input); 
       document.getElementById("div1").appendChild(br);
     }
    }
   */
   
    //使用jquery来添加元素
   $(function(){
    $("#btn").click(function(){
     var num=$("#num").val();
     $("#div1").html("");
     for(var i=0;i<num;i++){
      $("#div1").append("<input type='text' name='items'/> <br/>");
     }
     
    });
   });
    
 
   
   </script>
  </head>
 
  <body>
     <input type="text" name="items" id="num"/>&nbsp;
     <!--
     <input type="button" value="click" id="btn" οnclick="addItems()">
      -->
     <input type="button" value="click" id="btn" >
     <div id="div1"></div>
  </body>
</html>

=====================文件上传的file添加 和删除============================

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'demo1.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
 <script type="text/javascript" src="js/jquery-1.6.2.js"></script>
   <script type="text/javascript">
    //用javascirpt来控制的
   /*
    *
    *
    * function addItem(){
    var input=document.createElement("input");
     input.type="file";
     input.setAttribute("name","items");
     
    var button=document.createElement("input");
     button.type="button";
     button.setAttribute("value","删除");
    
     var br=document.createElement("br"); 
     
     document.getElementById("fileDiv")
     .appendChild(br);
     
     document.getElementById("fileDiv")
     .appendChild(input);
     
     document.getElementById("fileDiv")
     .appendChild(button);
     
     
     //给button注册单击事件
     
     button.οnclick=function(){
      //删除换行
      document.getElementById("fileDiv").removeChild(br);
      //删除file
      document.getElementById("fileDiv").removeChild(input);
      //删除自身button
      document.getElementById("fileDiv").removeChild(button);
     }
     
     
    } 
   
   */
   
   //用jquery来创建和控制
   
   $(function(){
    $("#more").click(function(){
     //获得div
     var div=$("#fileDiv");
     
     var br=$("<br/>");
     var file=$("<input type='file'/>");
     var btn=$("<input type='button' value='删除'/>");
     
     //追加
     div.append(br).append(file).append(btn);
     //删除
     btn.click(function(){
      br.remove();
      file.remove();
      btn.remove();
     });
     
    });
    
    
   });
   
   </script>
  </head>
 
  <body> <!-- js
     <input type="file">&nbsp;<input type="button" value="more" id="more" οnclick="addItem()"/>
     <div id="fileDiv"></div>
    -->
    <!-- jqeury示范 -->
    <input type="file">&nbsp;
    <input type="button" value="more" id="more"/>
     <div id="fileDiv"></div>
     
  </body>
</html>

 ======================元素克隆==========================

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'demo1.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
 <script type="text/javascript" src="js/jquery-1.6.2.js"></script>
   <script type="text/javascript">
    $(function(){
     $("ul li").click(function(){
      //这里会循环,用this代表当前对象 this是DOM,当clone(true)是克隆出来的元素也具备起克隆能力
      //$(this).clone().prependTo("ul");
      $(this).clone(true).prependTo("ul");
     });
    });
   </script>
  </head>
 
  <body>
     <p>元素克隆</p>
     <ul>
      <li>小王梅</li>
      <li>大王梅</li>
      <li>王梅</li>
      <li>爱王梅</li>
      <li>Love王梅</li>
     </ul>
  </body>
</html>

 

=========================

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值