小技巧2

 1 //屏蔽某个按键的作用
 2 
 3 function maskingKeyBoard() {
 4 
 5     if (event.keyCode == 65) {
 6         event.KeyCode = 0;
 7         event.returnValue = false;
 8         alert("当前的设置不允许使用键A");
 9     }
10     if (event.keyCode == 97) {
11         event.KeyCode = 0;
12         event.returnValue = false;
13         alert("当前的设置不允许使用键a");
14     }
15 }
16 
17 
18 <input name="UserPwd" type="password" onKeyPress="maskingKeyBoard()">           //在编辑框中调用函数

获取下拉列表的选择项  调用函数  onchange

1              <select name="oa" onchange="Fcolor()">
2                     <option value="red">红</option>
3                   <option value="white">白</option>
4                   <option value="black">黑</option>
5                   <option value="blue" selected="selected">蓝</option>
6                   <option value="green">绿</option>
7                   <option value="yellow">黄</option>
8              </select>

js文件中的函数的写法如下

1 function Fcolor() {
2     var e = window.event;
3     var obj = e.srcElement;
4     form1.textfiled.style.color = obj.options[obj.selectedIndex].value;
5 }

:3:跳转到页面就调用函数,其它的事件。而不是依托于的使用方法:

<body bgcolor=cyan  onload="startTime()">

4:radio常见的使用方法

 1 <body bgcolor="cyan">
 2     <form action="radio.jsp">
 3         <center>检验radio的功能</center>
 4 
 5         <p>
 6             1:A<input type="radio" name="one" value="A"> 中国 B<input
 7                 type="radio" name="one" value="B"> 美国 C<input type="radio"
 8                 name="one" value="C" /> 日本 D<input type="radio" name="one"
 9                 value="D" /> 韩国 <br />
10         <p>
11             2:A<input type="radio" name="two" value="A"> 汉语 B<input
12                 type="radio" name="two" value="B"> 英语C<input type="radio"
13                 name="two" value="C" /> 法语 D<input type="radio" name="two"
14                 value="D" /> 韩语 <input type="submit" name="sab" value="提交" />
15     </form>
16       <p>
17         <input type="button" name="sub" value="确定"  />
18 </body>

在后台通过数据比对检查选择的结果。。。

 1     String one = request.getParameter("one");
 2         String two = request.getParameter("two");
 3 
 4         String answer[] = { one, two };
 5         String result[] = { "A", "B" };
 6         int count = 0;
 7         for (int i = 0; i < result.length; i++) {
 8             if (answer[i].equals(result[i])) {
 9                 count++;
10             }
11         }
12     %>
13     <%=count%>

5.如何对一个字符串进行检验是否为空:

 1 <%!
 2         public String getString(String s){
 3         if(s==null)
 4             s = "";
 5         try{
 6             byte b[]=s.getBytes("ISO-8859-1");
 7             s = new String(b,"utf-8");
 8         }
 9         catch(Exception e){}
10         return s;    
11     }
12 %>

 

6session对象最简便的用法:获取数据、处理数据、后台交互、

 1 <%           
 2                  session.setAttribute("customer","顾客");
 3 %>
 4 
 5 
 6                  <input type="text" name="boy" /> 
 7 
 8 
 9 
10 <% 
11     String s = request.getParameter("boy");
12     session.setAttribute("name",s);
13 
14 %>
15                   <input type="text" name="buys" /> 
16 
17 
18 
19 
20 
21 <%    
22     String s = request.getParameter("buys");
23     session.setAttribute("goods",s);
24 %>
25 
26 
27 <% 
28     String 顾客 = (String)session.getAttribute("customer");
29     String 姓名 = (String)session.getAttribute("name");
30     String 商品 = (String)session.getAttribute("goods");
31         
32     姓名=getString(姓名);
33     商品=getString(商品);
34 %>
35 
36 
37         

7.直接通过js来获取鼠标在频幕上的位置以及按键的情况。

 1 //获取鼠标位置的函数
 2 var x = 0;
 3 var y =0;
 4 function MousePlace(){
 5     x = window.event.x;
 6     y = window.event.y;
 7     window.status="X:"+x+"  "+"Y:"+y+" ";
 8 }
 9 document.onmousemove = MousePlace;
10 //获取你按了那个键
11 function onAlert(){
12     if(window.event.keyCode==97)
13         {
14         alert("你按了a键");
15         }
16 }
17 document.onkeypress=onAlert;

 

 

 

 

 

 

 

 

 

posted @ 2013-08-26 15:45  最是那一杯红酒  阅读(184)  评论(0编辑  收藏  举报