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