js 回车键搜索

下面这个表示页面中只有一个回车键按钮的时候:

 

 
  
1 function document.onkeydown(){
2 if (event.keyCode == 13 ){
3 document.getElementById( " search_b " ).click();
4 return false ;
5 }
6 }

下面这样就表示取消回车键

 
  
1 if (window.event.keyCode == 13 ){
2 window.event.keyCode = 0 ;
3 }

 

下面这个表示页面中有两个回车键按钮的时候:

 

 
  
1 function document.onkeydown(){
2 var activeObj = document.activeElement;
3 if (event.keyCode == 13 ){
4 if (activeObj.name == " USER_PASS " || activeObj.name == " USER_ID " ) {
5 document.getElementById( " loginln " ).click();
6 return false ;
7 } else {
8 document.getElementById( " search_b " ).click();
9 return false ;
10 }
11 }
12 }

下面是html代码:

 

 

 
  
1 < input type ="image" name ="search_b" id ="search_b" src ="search.gif" border ="0" onclick ="javascript:document.submit();" >

 

 
  
1 <? php
2   /* *
3 *=================================================
4 *
5 * @author   hahawen(大龄青年) 
6 * @since   2004-12-04
7 * @copyright Copyright (c) 2004, NxCoder Group
8 *
9 *=================================================
10   */
11   /* *
12 * abstract class SimpleDocumentBase
13 * base class for xml file parse
14 * all this pachage's is work for xml file, and method is action as DOM.
15 *
16 * 1 add/update/remove data of xml file.
17 * 2 explode data to array.
18 * 3 rebuild xml file
19 *
20 * @package SmartWeb.common.xml
21 * @abstract
22 * @version 1.0
23   */
24   abstract class SimpleDocumentBase
25 {
26 private $nodeTag = null ;
27 private $attributes = array ();
28 private $values = array ();
29 private $nodes = array ();
30 function __construct( $nodeTag )
31 {
32 $this -> nodeTag = $nodeTag ;
33 }
34 public function getNodeTag()
35 {
36 return $this -> nodeTag;
37 }
38 public function setValues( $values )
39 {
40 $this -> values = $values ;
41 }
42 public function setValue( $name , $value )
43 {
44 $this -> values[ $name ] = $value ;
45 }
46 public function getValue( $name = null )
47 {
48 return $name == null ? $this -> values : $this -> values[ $name ];
49 }
50 public function removeValue( $name )
51 {
52 unset ( $this -> values[ " $name " ]);
53 }
54 public function setAttributes( $attributes )
55 {
56 $this -> attributes = $attributes ;
57 }
58 public function setAttribute( $name , $value )
59 {
60 $this -> attributes[ $name ] = $value ;
61 }
62 public function getAttribute( $name = null )
63 {
64 return $name == null ? $this -> attributes : $this -> attributes[ $name ];
65 }
66 public function removeAttribute( $name )
67 {
68 unset ( $this -> attributes[ " $name " ]);
69 }
70 public function getNodesSize()
71 {
72 return sizeof ( $this -> nodes);
73 }
74 protected function setNode( $name , $nodeId )
75 {
76 $this -> nodes[ $name ] = $nodeId ;
77 }
78 public abstract function createNode( $name , $attributes );
79 public abstract function removeNode( $name );
80 public abstract function getNode( $name = null );
81 protected function getNodeId( $name = null )
82 {
83 return $name == null ? $this -> nodes : $this -> nodes[ $name ];
84 }
85 protected function createNodeByName( $rootNodeObj , $name , $attributes , $pId )
86 {
87 $tmpObject = $rootNodeObj -> createNodeObject( $pId , $name , $attributes );
88 $key = isset ( $attributes [id]) ? $name .
89 ' _ ' . $attributes [id] : $name . ' _ ' . $this -> getNodesSize();
90 $this -> setNode( $key , $tmpObject -> getSeq());
91 return $tmpObject ;
92 }
93 protected function removeNodeByName( $rootNodeObj , $name )
94 {
95 $rootNodeObj -> removeNodeById( $this -> getNodeId( $name ));
96 if ( sizeof ( $this -> nodes) == 1 )
97 $this -> nodes = array ();
98 else
99 unset ( $this -> nodes[ $name ]);
100 }
101 protected function getNodeByName( $rootNodeObj , $name = null )
102 {
103 if ( $name == null )
104 {
105 $tmpList = array ();
106 $tmpIds = $this -> getNodeId();
107 foreach ( $tmpIds as $key => $id )
108 $tmpList [ $key ] = $rootNodeObj -> getNodeById( $id );
109 return $tmpList ;
110 } else
111 {
112 $id = $this -> getNodeId( $name );
113 if ( $id === null )
114 {
115 $tmpIds = $this -> getNodeId();
116 foreach ( $tmpIds as $tkey => $tid )
117 {
118 if ( strpos ( $key , $name ) == 0 )
119 {
120 $id = $tid ;
121 break ;
122 }
123 }
124 }
125 return $rootNodeObj -> getNodeById( $id );
126 }
127 }
128 public function findNodeByPath( $path )
129 {
130 $pos = strpos ( $path , ' | ' );
131 if ( $pos <= 0 )
132 {
133 return $this -> getNode( $path );
134 } else
135 {
136 $tmpObj = $this -> getNode( substr ( $path , 0 , $pos ));
137 return is_object ( $tmpObj ) ? $tmpObj -> findNodeByPath( substr ( $path , $pos + 1 )) : null ;
138 }
139 }
140 // 写入发送结果函数
141   public function info_write( $filename , $info_log )
142 {
143 $fp = fopen ( $filename , a);
144 // //出错,退出
145   if ( ! $fp )
146 {
147 exit ;
148 }
149 $info .= $info_log ;
150 $info .= " \r\n " ;
151 fwrite ( $fp , $info );
152 fclose ( $fp );
153 }
154 public function getSaveData()
155 {
156 $data = $this -> values;
157 if ( sizeof ( $this -> attributes) > 0 )
158 {
159 // $data[attrs] = $this->attributes;
160 }
161 $nodeList = $this -> getNode();
162 if ( $nodeList == null )
163 {
164 // unset ($data);
165 //return $data;
166 return true ;
167 }
168 foreach ( $nodeList as $key => $node )
169 {
170 $data [ $key ] = $node -> getSaveData();
171 if ( $data [id][value] != "" )
172 {
173
174 // $this->info_write("user/logic/sax_xml/modules/ok.txt",$data[id][value]);
175 }
176 // unset ($data);
177 }
178
179 echo " <pre> " ;
180 print_r ( $data );
181 return true ;
182 // return $data;
183 }
184
185 public function getSaveXml( $level = 0 )
186 {
187 $prefixSpace = str_pad ( "" , $level , "    " );
188 $str = " $prefixSpace < $this ->nodeTag " ;
189 foreach ( $this -> attributes as $key => $value )
190 $str .= " $key = " . $value . "" ;
191 $str .= " >
192 " ;
193 foreach ( $this -> values as $key => $value )
194 {
195 if ( is_array ( $value ))
196 {
197 $str .= " $prefixSpace   < $key " ;
198 foreach ( $value [attrs] as $attkey => $attvalue )
199 $str .= " $attkey = " . $attvalue . "" ;
200 $tmpStr = $value [value];
201 } else
202 {
203 $str .= " $prefixSpace   < $key " ;
204 $tmpStr = $value ;
205 }
206 $tmpStr = trim ( trim ( $tmpStr , "
207 " ));
208 $str .= ( $tmpStr === null || $tmpStr === "" ) ? " />
209 " : " > $tmpStr </ $key >
210 " ;
211 }
212 foreach ( $this -> getNode() as $node )
213 $str .= $node -> getSaveXml( $level + 1 ) . "
214 " ;
215 $str .= " $prefixSpace </ $this ->nodeTag> " ;
216 return $str ;
217 }
218 function __destruct()
219 {
220 unset ( $this -> nodes , $this -> attributes , $this -> values);
221 }
222 }
223 ?>

 

转载于:https://www.cnblogs.com/mmzwu/archive/2010/12/31/1923475.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值