首页 > 编程 > HTML > 正文

个人学习之作 hta

2020-01-25 19:40:56
字体:大 中 小
来源:转载
供稿:网友
  1. 这个hta是基于asp操作access数据库实现的,方便存储个人学习资料的一个东西,也是武林网的雏形,好不容易找到了备份,希望大家能喜欢 
  2. 复制代码 代码如下: 
  3. <!-- 
  4. *********************************************************************** 
  5. '*一直想做一个自己用来学习的东西,可是一直没有时间,本想用asp(用netbox)做的。,我一直 
  6. '*想学习程序,vb但没有时间学习,现在想用c#做一个,但没有什么时间,偶尔去官方找vbscript发现 
  7. '*这个不错的hta于是花了两三天的时间,做了一个这个,希望大家能喜欢。 
  8. '*Author: dxy(reterry) 
  9. '*version:1.0 
  10. '*QQ: 461478385 
  11. '*Email:douxy001@gmail.com 
  12. *********************************************************************** 
  13. //--> 
  14. <html> 
  15. <head> 
  16. <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
  17. <hta:application 
  18.      id="dxymdb" 
  19.   scroll="yes" 
  20.   singleinstance="yes" 
  21. border="thin" 
  22.   windowstate="maximize" 
  23. icon="dxy.ico" 
  24. > 
  25. <title>我的第一个hta程序</title> 
  26. <style type="text/css"> 
  27. <!-- 
  28. BODY 
  29. { 
  30.   scrollbar-face-color : #D8DBDF; 
  31.   scrollbar-highlight-color : #FFFFFF; 
  32.   scrollbar-shadow-color : #C1C6CC; 
  33.   scrollbar-3dlight-color : #ABB1B3; 
  34.   scrollbar-arrow-color : #7F8996; 
  35.   scrollbar-track-color : #F8FAF9; 
  36.   scrollbar-darkshadow-color : #ABB1B3; 
  37. } 
  38. body,td,th { 
  39.  font-size: 10pt; 
  40.  color: #FFFFFF; 
  41. } 
  42. body { 
  43.  background-color: #3a6ead; 
  44. } 
  45. a { 
  46.  font-size: 9pt; 
  47.  color: #000000; 
  48. } 
  49. a:link { 
  50.  text-decoration: none; 
  51.  color: #FFFF33; 
  52. } 
  53. a:visited { 
  54.  text-decoration: none; 
  55.  color: #FFFF33; 
  56. } 
  57. a:hover { 
  58.  text-decoration: none; 
  59.  color: #FFffff; 
  60. } 
  61. a:active { 
  62.  text-decoration: none; 
  63. } 
  64. .style4 {font-weight: bold} 
  65. .b { 
  66.  border-bottom-width: 1px; 
  67.  border-bottom-style: dashed; 
  68.  border-bottom-color: #BFDFFF; 
  69. } 
  70. .style9 {color: #ffff33} 
  71. input { 
  72. font-size:12px; 
  73. } 
  74. --> 
  75. </style> 
  76. </head> 
  77. <script language="vbscript"> 
  78. '加入智能显示信息条数 
  79. strComputer = "." 
  80.     Set objWMIService = GetObject("Winmgmts://" & strComputer & "/root/cimv2") 
  81.     Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor") 
  82.     For Each objItem in colItems 
  83.         thewidth = objItem.ScreenWidth 
  84.         theheight = objItem.ScreenHeight 
  85.     Next 
  86. '------------------智能结速----- 
  87. const adUserClient=3 
  88. sub window_onload() 
  89. dim conn 
  90. set conn=createobject("adodb.connection") 
  91. conn.open "provider=microsoft.jet.oledb.4.0;data source=db.mdb" 
  92. set rs=createobject("adodb.recordset") 
  93. rs.cursorlocation=adUserClient 
  94. sql="select * from theclass order by id desc" 
  95. rs.open sql,conn,1,1 
  96. rs.movefirst 
  97. strclasslist="<select onclick=changeclass() name=theclassname>" 
  98. strclassliststrclasslist=strclasslist+"<option value="&chr(34)&chr(34)&">" 
  99. do until rs.eof 
  100. strclassliststrclasslist=strclasslist&"<option value="&chr(34)&rs.fields.item("class_name")&chr(34)&">"&rs.fields.item("class_name")&"</option>" 
  101. rs.movenext 
  102. loop 
  103. strclassliststrclasslist=strclasslist&"<option value='其它'>其它</option><option value='全部'>全部</option></select>" 
  104. classlist.innerHTML=strclasslist 
  105. end sub 
  106. sub changeclass() 
  107. theclass.value=theclassname.value 
  108. if theclass.value="全部" then 
  109. theclass.value="" 
  110. end if 
  111. end sub 
  112. sub addclass() 
  113. classname=inputbox("请输入你要添加的类别","添加类别") 
  114. if classname="" then 
  115. msgbox "添加的类别不能为空" 
  116. exit sub 
  117. else 
  118. dim conn 
  119. set conn=createobject("adodb.connection") 
  120. conn.open "provider=microsoft.jet.oledb.4.0;data source=db.mdb" 
  121. set rs=createobject("adodb.recordset") 
  122. rs.cursorlocation=adUserClient 
  123. //sqla="insert into class(class_name)values("&classname&")" 
  124. rs.open "theclass",conn,3,3 
  125. rs.addnew() 
  126. rs("class_name")=classname 
  127. rs.update 
  128. rs.close 
  129. conn.close 
  130. msgbox classname&"添加成功",0 
  131. end if 
  132. call window_onload 
  133. end sub 
  134. sub delclass() 
  135. if confirm("你真的要删除吗?") then 
  136. delclassname=theclassname.value 
  137. if delclassname="" then 
  138. msgbox "要删除的类别不能为空" 
  139. exit sub 
  140. else 
  141. dim conn 
  142. set conn=createobject("adodb.connection") 
  143. conn.open "provider=microsoft.jet.oledb.4.0;data source=db.mdb" 
  144. set rs=createobject("adodb.recordset") 
  145. rs.cursorlocation=adUserClient 
  146. sqld="delete from theclass where class_name="&chr(39)&delclassname&chr(39) 
  147. rs.open sqld,conn,3,3 
  148. msgbox chr(34)&delclassname&chr(34)&"删除成功",0 
  149. //rs.close 
  150. //conn.close 
  151. end if 
  152. call window_onload 
  153. end if 
  154. end sub 
  155. sub editclass() 
  156. theeditclass=theclassname.value 
  157. reditclass=inputbox("请输入你要更改后的类别名称","类别修改") 
  158. if theeditclass="" or reditclass="" then 
  159. exit sub 
  160. else 
  161. dim conn 
  162. set conn=createobject("adodb.connection") 
  163. conn.open "provider=microsoft.jet.oledb.4.0;data source=db.mdb" 
  164. set rs=createobject("adodb.recordset") 
  165. rs.cursorlocation=adUserClient 
  166. sqld="update theclass set class_name="&chr(39)&reditclass&chr(39)&" where class_name="&chr(39)&theeditclass&chr(39) 
  167. rs.open sqld,conn,3,3 
  168. msgbox chr(34)&theeditclass&"-->"&reditclass&chr(34)&"成功修改",0 
  169. call window_onload 
  170. rs.close 
  171. conn.close 
  172. end if 
  173. end sub 
  174. sub window_onUnload 
  175. on error resume next 
  176. rs.close 
  177. conn.close 
  178. end sub 
  179. sub quitscript 
  180. on error resume next 
  181. rs.close 
  182. conn.close 
  183. self.close 
  184. end sub 
  185. sub unadd() 
  186. theclass.value="" 
  187. thetitle.value="" 
  188. content.value="" 
  189. theadd.style.display="none" 
  190. end sub 
  191. sub addnews() 
  192. theadd.style.display="block" 
  193. add.disabled=false 
  194. theclass.value=theclassname.value 
  195. getclass=theclass.value 
  196. gettitle=thetitle.value 
  197. getcontent=content.value 
  198. getisgood=isgood.value 
  199. if getisgood="" then 
  200. getisgood=0 
  201. else 
  202. getidgood=1 
  203. end if 
  204. if getclass<>"" and getclass<>"全部" and gettitle<>"" and getcontent<>"" then 
  205. //msgbox gettitle&getcontent 
  206. dim conn 
  207. set conn=createobject("adodb.connection") 
  208. conn.open "provider=microsoft.jet.oledb.4.0;data source=db.mdb" 
  209. set rs=createobject("adodb.recordset") 
  210. rs.cursorlocation=adUserClient 
  211. rs.open "list",conn,3,3 
  212. rs.addnew() 
  213. rs("title")=gettitle 
  214. rs("class_name")=getclass 
  215. rs("content")=getcontent 
  216. rs("isgood")=getisgood 
  217. rs.update 
  218. msgbox "恭喜,数据添加成功" 
  219. theclass.value="" 
  220. thetitle.value="" 
  221. content.value="" 
  222. end if 
  223. //rs.close 
  224. //conn.close 
  225. end sub 
  226. sub searchits() 
  227. thesearch=searchstr.value 
  228. 'if thesearch<>"" then 
  229. 'theclassname.value="" 
  230. 'end if 
  231. call changeit(1) 
  232. end sub 
  233. sub changeit(thenum) 
  234. theclass.value=theclassname.value 
  235. thename=theclassname.value 
  236. thesearch=searchstr.value 
  237. 'if thename<>"" then searchstr.value="" 
  238. thelist.innerHTML="" 
  239. thecounts.innerHTML="" 
  240. if thename<>"" or thesearch<>"" then 
  241. dim conn 
  242. set conn=createobject("adodb.connection") 
  243. conn.open "provider=microsoft.jet.oledb.4.0;data source=db.mdb" 
  244. set rs=createobject("adodb.recordset") 
  245. rs.cursorlocation=adUserClient 
  246. if thesearch="" then 
  247.   if thename="全部" then 
  248.   sql="select id,class_name,title,enter_time from list order by id desc" 
  249.   else 
  250.   sql="select id,class_name,title,enter_time from list where class_name='"&thename&"' order by id desc" 
  251.   end if 
  252. else 
  253.   if thename="" then 
  254.   sql="select distinct id,class_name,title,enter_time from list where (title like '%"&thesearch&"%' or content like '%"&thesearch&"%' or class_name like '%"&thesearch&"%')" 
  255.   else 
  256. sql="select distinct id,class_name,title,enter_time from list where (title like '%"&thesearch&"%' or content like '%"&thesearch&"%' or class_name like '%"&thesearch&"%') and class_name='"&thename&"'" 
  257.   end if 
  258. end if 
  259. rs.open sql,conn,1,1 
  260. page=trim(thenum) 
  261. if page<>"" then page=cint(page) 
  262. pre=true 
  263. last=true 
  264. if not rs.eof then 
  265. if theheight=600 then 
  266. maxperpage=20 
  267. elseif theheight>600 then 
  268. maxperpage=28 
  269. else 
  270. maxperpage=20 
  271. end if 
  272. rs.pagesize=maxperpage 
  273. thepages=rs.pagecount 
  274. thecount=rs.recordcount 
  275. if page="" and page<1 then 
  276. intpage=1 
  277. pre=false 
  278. else 
  279.    if page>thepages then 
  280.      intpage=thepages 
  281.   last=false 
  282.   else 
  283.     intpage=cint(page) 
  284.  end if 
  285. end if 
  286. themovenum=(intpage-1)*maxperpage 
  287. thecounts.innerHTML="共有<font color='#ffff33'>"&thecount&"</font>条信息[<font color='#ffff33'>"&maxperpage&"</font>条/页 共<font color='#ffff33'>"&thepages&"</font>页 当前第<font color='#ffff33'>"&page&"</font>页]" 
  288. rs.movefirst 
  289. if (intpage-1)*maxperpage<thecounts then 
  290. dim bookmark 
  291. bookmark=rs.bookmark 
  292. rs.move themovenum 
  293. end if 
  294. strlist="<table width='80%' align='center' cellpadding='0' cellspacing='1' border=0>" 
  295. for i=1 to maxperpage 
  296. if rs.eof then exit for 
  297. strliststrlist=strlist&"<tr><td height='20' class='b'>[<font color=yellow>"&rs("class_name")&"</font>] "&rs("title")&"  <font color='#f6f6f6'>"&rs("enter_time")&"</font>  <a href='#' onclick=openthecontent("&rs("id")&")>查看</a> <a href='#' onclick=editnews("&rs("id")&")>修改</a> <a href='#' onclick=delthecontent("&rs("id")&")>删除</a></td></td>" 
  298. rs.movenext 
  299. if rs.eof then exit for 
  300. next 
  301. strliststrlist=strlist&"</table>" 
  302. thelist.innerHTML=strlist 
  303. pagelist="第<select name='cpage' onchange=changeit2()>" 
  304. for j=1 to thepages 
  305. if j=intpage then 
  306. pagelistpagelist=pagelist&"<option value="&j&" selected>"&j&"</option>"  
  307. else 
  308. pagelistpagelist=pagelist&"<option value="&j&">"&j&"</option>"  
  309. end if 
  310. next 
  311. pagelistpagelist=pagelist&"</select>页" 
  312. fenye.innerHTML=pagelist 
  313. call changepage 
  314. else 
  315. thecounts.innerHTML="<font color='#ffff33'>对不起没有您要的信息</font>" 
  316. end if 
  317. end if 
  318. //rs.close 
  319. //conn.close 
  320. end sub 
  321. sub changeit2() 
  322. thenum=cpage.value 
  323. call changeit(thenum) 
  324. end sub 
  325. sub openthecontent(id) 
  326. theid=id 
  327. if id<>"" then 
  328. id=cint(id) 
  329. end if 
  330. dim conn 
  331. set conn=createobject("adodb.connection") 
  332. conn.open "provider=microsoft.jet.oledb.4.0;data source=db.mdb" 
  333. set rs=createobject("adodb.recordset") 
  334. rs.cursorlocation=adUserClient 
  335. sql="select * from list where id="&id&"" 
  336. rs.open sql,conn,1,1 
  337. if not rs.eof then 
  338. theopencontent=rs("content") 
  339. theopencontent=replace(theopencontent,"<","<") 
  340. theopencontent=replace(theopencontent,">",">") 
  341. set diswindow=window.open("about:blank","diswindow") 
  342. diswindow.document.body.style.fontSize="12px" 
  343. diswindow.focus() 
  344. diswindow.document.write("<html><head><scr"+"ipt>function saveit(){strDesktop='C://Documents and Settings//Administrator//桌面';var code=event.srcElement.parentElement.children[0].value;var objfso=new ActiveXObject('Scripting.FileSystemObject');var strname=prompt('请输入文件名和路',strDesktop+'//temp.vbs');if(strname!=''){var objfile=objfso.CreateTextFile(strname,2,true);objfile.Write(code);objfile.Close();}}function runit(){var code=event.srcElement.parentElement.children[0].value;var newwin=window.open('');newwin.opener=null;newwin.document.write(code);newwin.document.close();}</scr"+"ipt><meta http-equiv='Content-Type' content='text/html; charset=gb2312'><title>"+rs("title")+"</title><body style='margin:10px' bgcolor='#3a6ead'><table width='700' border='0' align='center' cellpadding='0' cellspacing='0'><tr><td><textarea rows='20' style='width:700; border:1px solid #808080; overflow:hidden;' onmouseover='this.style.posHeight=this.scrollHeight' onpropertychange='this.style.posHeight=this.scrollHeight' onload='this.style.posHeight=this.scrollHeight'>"+theopencontent+"</textarea><br><input type=button value='运行上面的代码[html]' onclick='runit()'> <input type=button value='保存' onclick='saveit()'></td></tr></table></body></html>") 
  345. diswindow.focus() 
  346. diswindow.document.close() 
  347. end if 
  348. end sub 
  349. sub delthecontent(strid) 
  350. if confirm("你真的要删除吗?") then 
  351. id=strid 
  352. if id<>"" then 
  353. id=cint(id) 
  354. end if 
  355. dim conn 
  356. set conn=createobject("adodb.connection") 
  357. conn.open "provider=microsoft.jet.oledb.4.0;data source=db.mdb" 
  358. set rs=createobject("adodb.recordset") 
  359. rs.cursorlocation=adUserClient 
  360. sql="delete from list where id="&id&"" 
  361. rs.open sql,conn,3,3 
  362. msgbox "成功删除" 
  363. else 
  364. exit sub 
  365. end if 
  366. end sub 
  367. sub changepage() 
  368. cpage_l=cint(cpage.length) 
  369. cpage_v=cint(cpage.value) 
  370. cpage_value="<a href='#' onclick='changeit(1)'>首页</a>  " 
  371. if cpage_v>1 then 
  372. cpage_valuecpage_value=cpage_value&"<a href='#' onclick='changeit("&cpage_v-1&")'>上一页</a>  " 
  373. end if 
  374. if cpage_v<cpage_l and cpage_v>=1 then 
  375. cpage_valuecpage_value=cpage_value&"<a href='#' onclick='changeit("&cpage_v+1&")'>下一页</a>  " 
  376. end if 
  377. cpage_valuecpage_value=cpage_value&"<a href='#' onclick='changeit("&cpage_l&")'>尾页</a>  " 
  378. dispage.innerHTML=cpage_value 
  379. end sub 
  380. sub editnews(strid) 
  381. theadd.style.display="block" 
  382. id=strid 
  383. if id<>"" then 
  384. id=cint(id) 
  385. end if 
  386. dim conn 
  387. set conn=createobject("adodb.connection") 
  388. conn.open "provider=microsoft.jet.oledb.4.0;data source=db.mdb" 
  389. set rs=createobject("adodb.recordset") 
  390. rs.cursorlocation=adUserClient 
  391. sql="select * from list where id="&id&"" 
  392. rs.open sql,conn,1,1 
  393. if not rs.eof then 
  394. titlee=rs("title") 
  395. contente=rs("content") 
  396. classname=rs("class_name") 
  397. end if 
  398. theclassname.value=classname 
  399. thetitle.value=titlee 
  400. content.value=contente 
  401. theid1.value=id 
  402. add.disabled=true 
  403. end sub 
  404. sub editsave() 
  405. id=theid1.value 
  406. edittitle=thetitle.value 
  407. editcontent=content.value 
  408. classname=theclass.value 
  409. if id<>"" then 
  410. dim conn 
  411. set conn=createobject("adodb.connection") 
  412. conn.open "provider=microsoft.jet.oledb.4.0;data source=db.mdb" 
  413. set rs=createobject("adodb.recordset") 
  414. rs.cursorlocation=adUserClient 
  415. sql="select id,class_name,title,content from list where id="&id&"" 
  416. rs.open sql,conn,3,3 
  417. rs("class_name")=classname 
  418. rs("title")=edittitle 
  419. rs("content")=editcontent 
  420. rs.update 
  421. if err.number=0 then 
  422. msgbox("数据修改成功") 
  423. end if 
  424. end if 
  425. theid1.value="" 
  426. thetitle.value="" 
  427. content.value="" 
  428. 'theclassname.value="" 
  429. theclass.value="" 
  430. theadd.style.display="none" 
  431. add.disabled=false 
  432. call changeit2() 
  433. end sub 
  434. </script> 
  435. <body style="margin:0px; "> 
  436. <table width="98" height="10" border="0" align="center" cellpadding="0" cellspacing="0"> 
  437.   <tr> 
  438.     <td></td> 
  439.   </tr> 
  440. </table> 
  441. <span name="theadd" id="theadd" style="display:none"> 
  442. <table width="760" border="0" align="center" cellpadding="0" cellspacing="0" style="border:1px dotted #ffffff "> 
  443.   <tr> 
  444.     <td style="line-height:150%; ">类    别: 
  445.       <input name="theclass" type="text" id="theclass" style="border:1px solid #808080;" size="10" maxlength="50">       
  446.       标题: 
  447.       <input name="thetitle" type="text" id="thetitle" size="40" maxlength="200">       
  448.       <input type="button" name="add" value="添加" onClick="addnews"> 
  449.       <input type="button" name="edit" value="修改" onClick="editsave"> 
  450.       <input type="button" name="undo" value="取消" onClick="unadd"> 
  451.       <br> 
  452.       添加内容: 
  453.       <span class="style4"> 
  454.       <textarea name="content" rows="15" style="border:1px solid #808080; width:760; work-break:break-all; " ondblclick="content.style.posHeight=content.scrollHeight"></textarea> 
  455.       </span>    <br> 
  456.       是否推荐:<input name="isgood" type="text" size="5"> 
  457.    <br> id值:     
  458.     <input name="theid1" type="text" size="5"></td> 
  459.   </tr> 
  460. </table> 
  461. </span><br> 
  462. <table width="760" height="47" border="0" align="center" cellpadding="0" cellspacing="0" style="border:1px dotted #ffffff;"> 
  463.    <tr> 
  464.     <td height="23" align="center"><div align="left"><span class="style9">内容列表</span> [ 
  465.       <input type="button" value="添加信息" onClick="addnews"> 
  466.       ] 类别:<span id="classlist"></span> 
  467. <input name="button" type="button" onClick="changeit(1)" value="载入"> 
  468. <input type="button" onClick="addclass" value="添加"'> 
  469.       <input type="button" onClick="delclass" value="删除"'> 
  470.       <input type="button" onClick="editclass" value="编辑"'> 
  471.       <input type="button" name="Submit" value="退出" onClick="quitscript"'> 
  472.         <input name="searchstr" type="text" id="searchstr"' onfocus="searchstr.select()"> 
  473.     <input type="submit" name="Submit" value="搜"' onClick="searchits"> 
  474. </div></td> 
  475.   </tr>   
  476.   <tr> 
  477.     <td><hr align="center" width="80%" size="1" noshade style="border:1px solid #ffffff "></td> 
  478.   </tr> 
  479.   <tr> 
  480.     <td align="center"><span id="fenyetop"></span></td> 
  481.   </tr> 
  482.   <tr> 
  483.     <td><span id="thelist"></span></td> 
  484.   </tr> 
  485.   <tr> 
  486.     <td align="center"><span id="thecounts"></span>  <span id="dispage"></span><span id="fenye"></span></td> 
  487.   </tr>    
  488. </table> 
  489. </body> 
  490. </html> 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表