200多个js技巧代码(2)

Stella981
• 阅读 465
51.向文件中写内容
<%@ page import="java.io.*" %>
<%
 String str = "print me";
 //always give the path from root. This way it almost always works.
 String nameOfTextFile = "/usr/anil/imp.txt";
 try
 {
  PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
  pw.println(str);
  //clean up
  pw.close();
 }
 catch(IOException e)
 {
  out.println(e.getMessage());
 }
%>

52.先读文件再写文件
<%@ page language = "java" %>
<%@ page contentType = "text/html; charSet=gb2312" %>
<%@ page import ="java.util.*" %>
<%@ page import ="java.lang.*" %>
<%@ page import ="javax.servlet.*" %>
<%@ page import ="javax.servlet.jsp.*" %>
<%@ page import ="javax.servlet.http.*" %>
<%@ page import="java.io.*" %>
eryrytry
<%
 int count=0;
 FileInputStream fi =new FileInputStream ("count.txt");
 ObjectInputStream si= new ObjectInputStream (fi);
 count =si.readInt();
 count++;
 out.print(count);
 si.close();

 FileOutputStream fo =new FileOutputStream ("count.txt");
 ObjectOutputStream so= new ObjectOutputStream (fo);
 so.writeInt(count);
 so.close();
%>

53.直线型输入框
<INPUT name=Password size=10 type=password style="border-left-width: 0; border-right-width: 0;

border-top-width: 0; border-bottom-style: solid; border-bottom-width: 1; background-color: #9CEB9C">

54.可以将背景改为按钮性状,通过改变css改变属性
<td width="65" align="center" bgcolor="#E0E0E0" onmouseover=this.className='mouseoverbt';

onmouseout=this.className='mouseout';><a href="tm.asp?classid=76"><font

color="#000000">录音笔</font></a></td>
<style>
.mouseoverbt
{
 background-image: url(http://www.yongle.com.cn/img/btbgw64h20y.gif);
 background-repeat: no-repeat;
}
.mouseout
{
 background-color: #E0E0E0;
}
</style>

55.同时按下CTRL和Q键
document.onkeydown=function()
{
if(event.ctrlKey&&event.keyCode==81)
{alert(1)}
}//

56.以下是一个完整的显示hint的代码,其思想是当鼠标停留是将div中的内容显示在鼠标出,当鼠标移出后在将该div隐

藏掉
---------------------------------------------------------------------------------------------------------

------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<style>
#hint{
 width:198px;
 border:1px solid #000000;
 background:#99ff33;
 position:absolute;
 z-index:9;
 padding:6px;
 line-height:17px;
 text-align:left;
 top: 1520px;
}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
function showme()
{
 var oSon=window.document.getElementById("hint");
 if (oSon==null) return;
 with (oSon)
 {
  innerText=guoguo.value;
  style.display="block";
  style.pixelLeft=window.event.clientX+window.document.body.scrollLeft+6;
  style.pixelTop=window.event.clientY+window.document.body.scrollTop+9;
 }
}
function hidme()
{
 var oSon=window.document.getElementById("hint");
 if (oSon==null) return;
 oSon.style.display="none";
}
//-->
</SCRIPT>
<BODY>
<text id=guoguo value=ga>
<a href=# onmouseover=showme() onmouseout=hidme() onmousemove=showme() son=hint>dfdfd</a>
<div id=hint style="display:none"></div>
</BODY>
</HTML>
---------------------------------------------------------------------------------------------------------

------------

57.弹出窗口
方法一:<body onload="openwen()"> 浏览器读页面时弹出窗口;
方法二:<body onunload="openwen()"> 浏览器离开页面时弹出窗口;
方法三:用一个连接调用:<a href="#" onclick="openwin()">打开一个窗口</a>
注意:使用的"#"是虚连接。
方法四:用一个按钮调用:<input type="button" onclick="openwin()" value="打开窗口"> 何时装载script


58.动态改变字体的大小
function doZoom(size)
{
   document.getElementById('zoom').style.fontSize=size+'px'
}

function aa()
{
   var newWin=window.open(url);
   newWin.document.form1.text1.value=value1;
}改变弹出窗口上域的属性
opener.document.form2.text2.value=value2;改变父窗口的域的值

59.判断是何种浏览器
var name = navigator.appName;
if (name == "Microsoft Internet Explorer")
 alert("IE");
else if (name == "Netscape")
 alert("NS");//

60.vbsscript确定框
<script language="VBScript">
<!--
MsgBox "确定删除吗?", 4
//-->
</script>//

61.复制内容到剪切板
function JM_cc(bb)
{
    var ob=eval("document.form1."+bb);
    ob.select();
    js=ob.createTextRange();
    js.execCommand("Copy");
}//

62.java中建立数据库连接取数据
public void init()
{
 String url="jdbc:odbc:javadata";
 try
 {
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  Connection con=DriverManager.getConnection(url,"sa","");//mssql database user SA and password
  DatabaseMetaData dma=con.getMetaData();
  System.out.println("Connect to"+dma.getURL());
  System.out.println(";Driver "+dma.getDriverName());
  System.out.println(";Version "+dma.getDriverVersion());
  System.out.println("");
  Statement stmt=con.createStatement();
  ResultSet rs=stmt.executeQuery("select * from company.dbo.TB_NAME where number=1");//Sql
  rs.next();
  String dispresult=rs.getString("name");
  System.out.println(dispresult);// Instead,you can display it in Paint() or use AWT etc.
  rs.close();
  stmt.close();
  con.close();
 }
 catch(SQLException ex)
 {
  System.out.println("!!!SQL Exception !!!");
  while(ex!=null)
  {
   System.out.println("SQLState:"+ex.getSQLState());
   System.out.println("Message:"+ex.getMessage());
   System.out.println("Vendor:"+ex.getErrorCode());
   ex=ex.getNextException();
   System.out.println("");
  }

 }
 catch(java.lang.Exception ex)
 {
  ex.printStackTrace();
 }
}//


63.最小化窗口
window.blur()//


64.文档的路径
document.URL//

65.定时执行某段程序
setTimeout("change_color()",600);

66.设置为主页
function makeHome(){
  netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
  navigator.preference("browser.startup.homepage", location.href);
}//

67.设置为收藏
function addFav(){
  if(ie)
    window.external.AddFavorite(location.href,'WWW.OGRISH.COM : GROTESQUE MOVIES AND PICTURES');
  if(ns)
    alert("Thanks for the bookmark!\n\nNetscape users click OK then press CTRL-D");
}//

68.判断cookie是否可用
navigator.cookieEnabled;//

69.显示有模式的有页面的弹出窗口
function setbgcolor_onclick()
{
 var color = showModalDialog("/mailpage/compose/colorsel.html",0,"help=0");
 if (color != null)
 {
  document.compose.bgcolor.value = color;
 }
}//


70.截取小数点后两位
var a=3454545.4454545;
alert(a.toFixed(2));//


71.禁止选择页面上的文字来拷贝
<script>
function noEffect() {
  with (event) {
    returnValue = false;
    cancelBubble = true;
  }
  return;
}
</script>
<body onselectstart="noEffect()" oncontextmenu="noEffect()">//

72.屏蔽右键菜单
oncontextmenu="event.returnValue = false"//

73.事件禁止起泡
event.cancelBubble = true//

74.禁止在输入框打开输入法
<input style="ime-mode: disabled">//

75.屏蔽汉字和空格
<input name="txt"><input type="submit" onClick="alert(!/[^ -}]|\s/.test(txt.value))">//

76.用javascript判断文件是否存在
function Exists(filespec)
{
 if (filespec)
 {
  var fso;
  fso = new ActiveXObject("Scripting.FileSystemObject");
  alert(fso.FileExists(filespec));
 }
}
选择图片 <input type=file name=f1><p>
<input type="submit" onClick="Exists(f1.value)">//

77.获得当前的文本框选中的文字
<input onmouseup="alert(document.selection.createRange().text)" value=123>//

78.跳转至目标页面,同时不可返回
<a href="javascript:location.replace('http://www.sohu.com/')">sohu.com</a>//

 
79.获得当前的行是表格的第几行
<script>
function getrow(obj)
{
   if(event.srcElement.tagName=="TD"){
   curRow=event.srcElement.parentElement;
   alert("这是第"+(curRow.rowIndex+1)+"行");

   }
}
</script>

<table border="1" width="100%" onclick=getrow(this)>
  <tr>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
  </tr>
  <tr>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
  </tr>
</table>//

80.删除表格某行,xx表示某行,下标从0开始计算
document.all.myTable.deleteRow(xx)//

81.动态的向表格中添加行
<table id="t1" border="1">
</table>
<script language="JavaScript">
function add()
{
   t1.insertRow().insertCell().innerHTML = '<input name="test'+t1.rows.length+'">';
}//
点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Stella981 Stella981
2年前
Android So动态加载 优雅实现与原理分析
背景:漫品Android客户端集成适配转换功能(基于目标识别(So库35M)和人脸识别库(5M)),导致apk体积50M左右,为优化客户端体验,决定实现So文件动态加载.!(https://oscimg.oschina.net/oscnet/00d1ff90e4b34869664fef59e3ec3fdd20b.png)点击上方“蓝字”关注我
Wesley13 Wesley13
2年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Stella981 Stella981
2年前
HIVE 时间操作函数
日期函数UNIX时间戳转日期函数: from\_unixtime语法:   from\_unixtime(bigint unixtime\, string format\)返回值: string说明: 转化UNIX时间戳(从19700101 00:00:00 UTC到指定时间的秒数)到当前时区的时间格式举例:hive   selec
可莉 可莉
2年前
200多个js技巧代码(2)
51.向文件中写内容<%@ page import"java.io." %<% String str  "print me"; //always give the path from root. This way it almost always works. String nameOfTex
Wesley13 Wesley13
2年前
35岁是技术人的天花板吗?
35岁是技术人的天花板吗?我非常不认同“35岁现象”,人类没有那么脆弱,人类的智力不会说是35岁之后就停止发展,更不是说35岁之后就没有机会了。马云35岁还在教书,任正非35岁还在工厂上班。为什么技术人员到35岁就应该退役了呢?所以35岁根本就不是一个问题,我今年已经37岁了,我发现我才刚刚找到自己的节奏,刚刚上路。
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
2个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这