searchreplace.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <title>查找替换</title>
  6. <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
  7. <script type="text/javascript" src="../internal.js"></script>
  8. <style type="text/css">
  9. *{color: #838383}
  10. body {
  11. font-size: 12px;
  12. width:380px;
  13. height: 170px;
  14. overflow: hidden;
  15. margin:0px;padding:0px;
  16. }
  17. .warp{
  18. padding: 39px 0px 0px 15px;
  19. height:88%;position:relative;
  20. }
  21. * +html .warp{height:80%}
  22. .head{position:absolute;height:31px;top:9px;}
  23. .content{height:110px;border: 1px solid #ddd;padding:5px}
  24. .head span{width:62px;height:29px;line-height:29px;background:red;display:block;float: left;text-align: center;margin-right: 1px;cursor: pointer }
  25. .head span.def{background:url("../../themes/default/images/dialog-title-bg.png") repeat-x;border:1px solid #ccc;}
  26. .head span.act{background:#FFF;border:1px solid #ccc;border-bottom: 1px solid #FFF}
  27. .content table{width:100%;}
  28. .content input.int{ width:190px;height:21px;background: #FFF;border:1px solid #d7d7d7;padding: 0px; margin: 0px;line-height:21px;}
  29. .content input.btn{width:60px; text-align:center;line-height:24px; text-decoration: none;height:24px;border: 0px;margin:0px;padding:0px;background:url("../../themes/default/images/dialog-title-bg.png") repeat-x;border:1px solid #ccc; }
  30. </style>
  31. </head>
  32. <body>
  33. <div class="warp">
  34. <div id="head" class="head">
  35. <span name="find" class="act">查找</span> <span name="replace" class="def">替换</span>
  36. </div>
  37. <div class="content" id="find">
  38. <table>
  39. <tr>
  40. <td width="80">查找:</td>
  41. <td><input id="findtxt" type="text" class="int" /></td>
  42. </tr>
  43. <tr>
  44. <td>区分大小写:</td>
  45. <td>
  46. <input id="matchCase" type="checkbox" />
  47. </td>
  48. </tr>
  49. <tr>
  50. <td colspan="2">
  51. <input id="nextFindBtn" type="button" value="下一个" class="btn" />
  52. <input id="preFindBtn" type="button" value="上一个"class="btn" />
  53. </td>
  54. </tr>
  55. </table>
  56. </div>
  57. <div class="content" id="replace">
  58. <table>
  59. <tr>
  60. <td width="80">查找:</td>
  61. <td><input id="findtxt1" type="text" class="int" /></td>
  62. </tr>
  63. <tr>
  64. <td>替换:</td>
  65. <td><input id="replacetxt" type="text" class="int" /></td>
  66. </tr>
  67. <tr>
  68. <td>区分大小写:</td>
  69. <td>
  70. <input id="matchCase1" type="checkbox" />
  71. </td>
  72. </tr>
  73. <tr>
  74. <td colspan="2">
  75. <input id="nextReplaceBtn" type="button" value="下一个" class="btn" />
  76. <input id="preReplaceBtn" type="button" value="上一个" class="btn" />
  77. <input id="repalceBtn" type="button" value="替换" class="btn" />
  78. <input id="allrepalceBtn" type="button" value="全部替换" class="btn" />
  79. </td>
  80. </tr>
  81. </table>
  82. </div>
  83. </div>
  84. <script type="text/javascript">
  85. //清空上次查选的痕迹
  86. editor.firstForSR = 0;
  87. editor.currentRangeForSR = null;
  88. $G("replace").style.display = "none";
  89. //给tab注册切换事件
  90. function toggletab(){
  91. var tabs = document.getElementsByTagName("span");
  92. for(var i=0,j;j=tabs[i];i++){
  93. domUtils.on(j,"click",function(){
  94. var name = this.getAttribute("name");
  95. var spans = document.getElementsByTagName("span");
  96. var len = spans.length;
  97. for(var s=0;s<len;s++){
  98. spans[s].className = 'def';
  99. }
  100. this.className = 'act';
  101. $G("find").style.display = "none";
  102. $G("replace").style.display = "none";
  103. $G(name).style.display = "";
  104. $G('findtxt1').value = $G('findtxt').value;
  105. if(name =="replace"){
  106. $focus($G("findtxt1"));
  107. }else{
  108. $focus($G("findtxt"));
  109. }
  110. });
  111. }
  112. }
  113. //是否区分大小写
  114. function getMatchCase (id){
  115. return $G(id).checked ? true : false;
  116. }
  117. //查找
  118. $G("nextFindBtn").onclick = function(txt,dir,mcase){
  119. var findtxt = $G("findtxt").value,obj;
  120. if(!findtxt){
  121. return false;
  122. }
  123. obj = {
  124. searchStr : findtxt,
  125. dir : 1,
  126. casesensitive : getMatchCase("matchCase")
  127. };
  128. if(!frCommond(obj)){
  129. alert("已经搜索到文章底部!");
  130. }
  131. }
  132. $G("nextReplaceBtn").onclick = function(txt,dir,mcase){
  133. var findtxt = $G("findtxt1").value,obj;
  134. if(!findtxt){
  135. return false;
  136. }
  137. obj = {
  138. searchStr : findtxt,
  139. dir : 1,
  140. casesensitive : getMatchCase("matchCase1")
  141. };
  142. frCommond(obj);
  143. }
  144. $G("preFindBtn").onclick = function(txt,dir,mcase){
  145. var findtxt = $G("findtxt").value,obj;
  146. if(!findtxt){
  147. return false;
  148. }
  149. obj = {
  150. searchStr : findtxt,
  151. dir : -1,
  152. casesensitive : getMatchCase("matchCase")
  153. };
  154. if(!frCommond(obj)){
  155. alert("已经搜索到文章顶部!");
  156. }
  157. }
  158. $G("preReplaceBtn").onclick = function(txt,dir,mcase){
  159. var findtxt = $G("findtxt1").value,obj;
  160. if(!findtxt){
  161. return false;
  162. }
  163. obj = {
  164. searchStr : findtxt,
  165. dir : -1,
  166. casesensitive : getMatchCase("matchCase1")
  167. };
  168. frCommond(obj);
  169. }
  170. //替换
  171. $G("repalceBtn").onclick = function(){
  172. var findtxt = $G("findtxt1").value.replace(/^\s|\s$/g,""),obj,
  173. replacetxt = $G("replacetxt").value.replace(/^\s|\s$/g,"");
  174. if(!findtxt){
  175. return false;
  176. }
  177. if(findtxt == replacetxt || (!getMatchCase("matchCase1") && findtxt.toLowerCase() == replacetxt.toLowerCase())){
  178. return false;
  179. }
  180. obj = {
  181. searchStr : findtxt,
  182. dir : 1,
  183. casesensitive : getMatchCase("matchCase1"),
  184. replaceStr : replacetxt
  185. };
  186. frCommond(obj);
  187. }
  188. //全部替换
  189. $G("allrepalceBtn").onclick = function(){
  190. var findtxt = $G("findtxt1").value.replace(/^\s|\s$/g,""),obj,
  191. replacetxt = $G("replacetxt").value.replace(/^\s|\s$/g,"");
  192. if(!findtxt){
  193. return false;
  194. }
  195. if(findtxt == replacetxt || (!getMatchCase("matchCase1") && findtxt.toLowerCase() == replacetxt.toLowerCase())){
  196. return false;
  197. }
  198. obj = {
  199. searchStr : findtxt,
  200. casesensitive : getMatchCase("matchCase1"),
  201. replaceStr : replacetxt,
  202. all : true
  203. };
  204. var num = frCommond(obj);
  205. if(num){
  206. alert("总共替换了"+num+"个内容!");
  207. }
  208. }
  209. //执行
  210. var frCommond = function(obj){
  211. return editor.execCommand("searchreplace",obj);
  212. }
  213. toggletab();
  214. </script>
  215. </body>
  216. </html>