js应用3

xml 代码
  1. 57.弹出窗口   
  2. 方法一:<body onload="openwen()"> 浏览器读页面时弹出窗口;    
  3. 方法二:<body onunload="openwen()"> 浏览器离开页面时弹出窗口;    
  4. 方法三:用一个连接调用:<a href="#" onclick="openwin()">打开一个窗口</a>    
  5. 注意:使用的"#"是虚连接。    
  6. 方法四:用一个按钮调用:<input type="button" onclick="openwin()" value="打开窗口"> 何时装载script   
  7.   
  8.   
  9. 58.动态改变字体的大小   
  10. function doZoom(size)   
  11. {   
  12.    document.getElementById('zoom').style.fontSize=size+'px'   
  13. }   
  14.   
  15. function aa()   
  16. {   
  17.    var newWin=window.open(url);   
  18.    newWin.document.form1.text1.value=value1;   
  19. }改变弹出窗口上域的属性   
  20. opener.document.form2.text2.value=value2;改变父窗口的域的值   
  21.   
  22. 59.判断是何种浏览器   
  23. var name = navigator.appName;   
  24. if (name == "Microsoft Internet Explorer")   
  25.  alert("IE");   
  26. else if (name == "Netscape")   
  27.  alert("NS");//   
  28.   
  29. 60.vbsscript确定框   
  30. <script language="VBScript">  
  31. <!--   
  32. MsgBox "确定删除吗?", 4    
  33. //-->  
  34. </script>//   
  35.   
  36. 61.复制内容到剪切板   
  37. function JM_cc(bb)   
  38. {   
  39.     var ob=eval("document.form1."+bb);   
  40.     ob.select();   
  41.     js=ob.createTextRange();   
  42.     js.execCommand("Copy");   
  43. }//   
  44.   
  45. 62.java中建立数据库连接取数据   
  46. public void init()   
  47. {   
  48.  String url="jdbc:odbc:javadata";   
  49.  try   
  50.  {   
  51.   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");   
  52.   Connection con=DriverManager.getConnection(url,"sa","");//mssql database user SA and password   
  53.   DatabaseMetaData dma=con.getMetaData();   
  54.   System.out.println("Connect to"+dma.getURL());   
  55.   System.out.println(";Driver "+dma.getDriverName());   
  56.   System.out.println(";Version "+dma.getDriverVersion());   
  57.   System.out.println("");   
  58.   Statement stmt=con.createStatement();   
  59.   ResultSet rs=stmt.executeQuery("select * from company.dbo.TB_NAME where number=1");//Sql    
  60.   rs.next();   
  61.   String dispresult=rs.getString("name");   
  62.   System.out.println(dispresult);// Instead,you can display it in Paint() or use AWT etc.   
  63.   rs.close();   
  64.   stmt.close();   
  65.   con.close();   
  66.  }   
  67.  catch(SQLException ex)   
  68.  {   
  69.   System.out.println("!!!SQL Exception !!!");   
  70.   while(ex!=null)   
  71.   {   
  72.    System.out.println("SQLState:"+ex.getSQLState());   
  73.    System.out.println("Message:"+ex.getMessage());   
  74.    System.out.println("Vendor:"+ex.getErrorCode());   
  75.    exex=ex.getNextException();   
  76.    System.out.println("");   
  77.   }   
  78.   
  79.  }   
  80.  catch(java.lang.Exception ex)   
  81.  {   
  82.   ex.printStackTrace();   
  83.  }   
  84. }//   
  85.   
  86.   
  87. 63.最小化窗口   
  88. window.blur()//   
  89.   
  90.   
  91. 64.文档的路径   
  92. document.URL//   
  93.   
  94. 65.定时执行某段程序   
  95. setTimeout("change_color()",600);   
  96.   
  97. 66.设置为主页   
  98. function makeHome(){   
  99.   netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");   
  100.   navigator.preference("browser.startup.homepage", location.href);   
  101. }//   
  102.   
  103. 67.设置为收藏   
  104. function addFav(){   
  105.   if(ie)   
  106.     window.external.AddFavorite(location.href,'WWW.OGRISH.COM : GROTESQUE MOVIES AND PICTURES');   
  107.   if(ns)   
  108.     alert("Thanks for the bookmark!\n\nNetscape users click OK then press CTRL-D");   
  109. }//   
  110.   
  111. 68.判断cookie是否可用   
  112. navigator.cookieEnabled;//   
  113.   
  114. 69.显示有模式的有页面的弹出窗口   
  115. function setbgcolor_onclick()   
  116. {   
  117.  var color = showModalDialog("/mailpage/compose/colorsel.html",0,"help=0");   
  118.  if (color != null)   
  119.  {   
  120.   document.compose.bgcolor.value = color;   
  121.  }   
  122. }//   
  123.   
  124.   
  125. 70.截取小数点后两位   
  126. var a=3454545.4454545;   
  127. alert(a.toFixed(2));//   
  128.   
  129.   
  130. 71.禁止选择页面上的文字来拷贝   
  131. <script>  
  132. function noEffect() {   
  133.   with (event) {   
  134.     returnValue = false;   
  135.     cancelBubble = true;   
  136.   }   
  137.   return;   
  138. }   
  139. </script>  
  140. <body onselectstart="noEffect()" oncontextmenu="noEffect()">//   
  141.   
  142. 72.屏蔽右键菜单   
  143. oncontextmenu="event.returnValue = false"//   
  144.   
  145. 73.事件禁止起泡   
  146. event.cancelBubble = true//   
  147.   
  148. 74.禁止在输入框打开输入法   
  149. <input style="ime-mode: disabled">//   
  150.   
  151. 75.屏蔽汉字和空格   
  152. <input name="txt"><input type="submit" onClick="alert(!/[^ -}]|\s/.test(txt.value))">//   
  153.   
  154. 76.用javascript判断文件是否存在   
  155. function Exists(filespec)   
  156. {   
  157.  if (filespec)   
  158.  {   
  159.   var fso;   
  160.   fso = new ActiveXObject("Scripting.FileSystemObject");   
  161.   alert(fso.FileExists(filespec));   
  162.  }   
  163. }   
  164. 选择图片 <input type=file name=f1><p>  
  165. <input type="submit" onClick="Exists(f1.value)">//   
  166.   
  167. 77.获得当前的文本框选中的文字   
  168. <input onmouseup="alert(document.selection.createRange().text)" value=123>//   
  169.   
  170. 78.跳转至目标页面,同时不可返回   
  171. <a href="javascript:location.replace('http://www.sohu.com/')">sohu.com</a>//   
  172.   
  173.     
  174. 79.获得当前的行是表格的第几行   
  175. <script>  
  176. function getrow(obj)   
  177. {   
  178.    if(event.srcElement.tagName=="TD"){   
  179.    curRow=event.srcElement.parentElement;   
  180.    alert("这是第"+(curRow.rowIndex+1)+"行");   
  181.   
  182.    }   
  183. }   
  184. </script>  
  185.   
  186. <table border="1" width="100%" onclick=getrow(this)>  
  187.   <tr>  
  188.     <td width="20%"> </td>  
  189.     <td width="20%"> </td>  
  190.     <td width="20%"> </td>  
  191.     <td width="20%"> </td>  
  192.     <td width="20%"> </td>  
  193.   </tr>  
  194.   <tr>  
  195.     <td width="20%"> </td>  
  196.     <td width="20%"> </td>  
  197.     <td width="20%"> </td>  
  198.     <td width="20%"> </td>  
  199.     <td width="20%"> </td>  
  200.   </tr>  
  201. </table>//   
  202.   
  203. 80.删除表格某行,xx表示某行,下标从0开始计算   
  204. document.all.myTable.deleteRow(xx)//   
  205.   
  206. 81.动态的向表格中添加行   
  207. <table id="t1" border="1">  
  208. </table>  
  209. <script language="JavaScript">  
  210. function add()   
  211. {   
  212.    t1.insertRow().insertCell().innerHTML = '<input name="test'+t1.rows.length+'">';   
  213. }//   
  214.   
  215.     
  216.   
  217. 82.event.x,event.clientX,event.offsetX区别:   
  218. x:设置或者是得到鼠标相对于目标事件的父元素的外边界在x坐标上的位置。 clientX:相对于客户区域的x坐标位置,不   
  219.   
  220. 包括滚动条,就是正文区域。 offsetx:设置或者是得到鼠标相对于目标事件的父元素的内边界在x坐标上的位置。    
  221. screenX:相对于用户屏幕。    
  222.   
  223.     
  224. 83.显示是鼠标按钮的哪个   
  225. <body onMouseDown="alert(event.button)">点Mouse看看//   
  226.   
  227. 84.打开C盘   
  228. <form action="file:///c|/"><input type="submit" value="c:\ drive"></form>//   
  229.     
  230. 85.当前屏幕的分辨率   
  231. screen.width、screen.height//   
  232.   
  233. 86.设置表格中的内容   
  234. tbl.rows[0].cells[1].innerText=document.form.text1.value;//   
  235.   
  236.     
  237. 87.本地快捷键   
  238. <p><a href="file:///::{208D2C60-3AEA-1069-A2D7-08002B30309D}" target="_blank">网上邻居</a></p>  
  239. <p><a href="file:///::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\d:\web" target="_blank">我的电脑</a></p>  
  240. <p><a href="file:///::{450D8FBA-AD25-11D0-98A8-0800361B1103}" target="_blank">我的文档</a></p>  
  241. <p><a href="file:///::{645FF040-5081-101B-9F08-00AA002F954E}" target="_blank">回收站</a></p>  
  242. <p><a href="file:///::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"    
  243.   
  244. target="_blank">控制面板</a></p>  
  245. <p><a href="file:///::{7007ACC7-3202-11D1-AAD2-00805FC1270E}">拨号网络</a>(windows 2000)</p>  
  246.   
  247.      
  248. 88.IE菜单   
  249. <button onclick="min.Click()"><font face="webdings">0</font></button>//改变按钮上的图片   
  250. <input type=button  onclick="document.execCommand('CreateLink','true','true')"> //创建新连接   
  251. <input type=button  onclick="document.execCommand('print','true','true')"> //打印   
  252. <input type=button  onclick="document.execCommand('saveas','true','网站制作.htm')">//另存为htm   
  253. <input type=button  onclick="document.execCommand('saveas','true','网站制作.txt')">//另存为txt   
  254. document.execCommand("SaveAs")//保存为   
  255. document.execCommand('undo')//撤销上一次操作   
  256.   
  257. 89.web对话框   
  258. <SCRIPT>  
  259. var contents='<style>body,td{font:menu}img{cursor:hand}</style>';   
  260. contents+='<title>你要关闭我吗</title>';   
  261. contents+='<body bgcolor=menu>';   
  262. contents+='<table width=100height=100border=0>';   
  263. contents+='<tr><td align=center>';   
  264. contents+='你要关闭我吗?<br>';   
  265. contents+='<img src=dark.gif onclick=self.close() alt="...关闭">';   
  266. contents+='<img src=jet.gif onclick=self.close() alt="全是关闭">';   
  267. contents+='</td></tr></table>';   
  268. showModalDialog("about:"+contents+"","","dialogHeight:50px;dialogWidth:250px;help:no;status:no")   
  269. document.write(contents);   
  270. </SCRIPT>//   
  271.   
  272. 90.取第x,y的值   
  273. <button onclick="t1.rows[x].cells[y].innerText='guoguo'"></button>//   
  274.   
  275. 91.向新打开的网页上写内容   
  276. newwin=window.open('about:blank','','top=10');   
  277. newwin.document.write('');//   
  278.   
  279. 93.返回   
  280. javascript:history.go(-2);//   
  281.   
  282. 94.将页面上选中的内容复制到剪贴板   
  283. abcdefg   
  284. <input type='button'    
  285.   
  286. onclick="window.clipboardData.setData('text',document.selection.createRange().text);" value='复制页面选中   
  287.   
  288. 的字符'>//   
  289. 95.将页面上选中的内容复制到剪贴板   
  290. <INPUT TYPE="text" NAME="">kjhkjhkhkj<INPUT TYPE="button" onclick="document.execCommand('Copy', 'false',    
  291.   
  292. null);">   
  293.   
  294. 96.鼠标移到下拉框时自动全部打开   
  295. <select onmouseover="javascript:this.size=this.length" onmouseout="javascript:this.size=1"></select>//   
  296.   
  297. 97.获得本机的文件   
  298. var fso = new ActiveXObject("Scripting.FileSystemObject");    
  299. var f1 = fso.GetFile("C:\\bsitcdata\\ejbhome.xml");    
  300. alert("File last modified: " + f1.DateLastModified); //   
  301.   
  302. 98.判断客户端是否是IE浏览器   
  303. 因为 document.all 是 IE 的特有属性,所以通常用这个方法来判断客户端是否是IE浏览器 ,document.all?1:0;   
  304.   
  305. 99.创建新的下拉框选项   
  306. new Option(text,value)这样的函数//   
  307.   
  308. 100.在页面上画柱状图   
  309. <STYLE>  
  310. td{font-size:12px}   
  311. body{font-size:12px}   
  312. v\:*{behavior:url(#default#VML);} //这里声明了v作为VML公用变量   
  313. </STYLE>  
  314. <SCRIPT LANGUAGE="JavaScript">  
  315. mathstr=12;   
  316. document.write ("<v:rect fillcolor='red'    
  317.   
  318. style='width:20;color:navy;height:"+5000/(1000/mathstr)+"'><br>&nbsp;%"+mathstr+"<br>4人<v:Extrusion    
  319.   
  320. backdepth='15pt' on='true'/></v:rect>")   
  321. </SCRIPT>  
  322. <v:rect fillcolor='red' style='width:20;color:navy;height:200'><br>%12<br>4人<v:Extrusion    
  323.   
  324. backdepth='15pt' on='true'/></v:rect>  
  325. <v:rect fillcolor='yellow' style='width:20;color:navy;height:100'><br>%12<br>4人<v:Extrusion    
  326.   
  327. backdepth='15pt' on='true'/></v:rect>//   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值