个人整理常用JS代码
1: tr变色
onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='#BFDFFF'"
2: button加个连接
<input type="button" name="fanhui" class="buttom" onClick="window.location.href='user.do?method=findDep&&tar=toadd'">
3:得到option的text
obj.options[obj.selectedIndex].text
点击保存
saveImage.document.execCommand('saveAs');">
4:得到参数值
document.all('username').value
document.getElementById()
document.getElementsByName()
5: 去左右空格
s = s.replace(/^\s*(.*?)\s*$/ig,'$1');
6:限制只能输入数字
onkeyup="value=value.replace(/[^\d]/g,'')"
7:
<input type="button" name="fanhui" value="返回" class="buttom" onClick="javascript:history.go(-1);">
8: 关闭窗口
<a href="#" onClick="window.close()">关闭窗口</a>
<input type="button" name="fanhui" value="关闭" class="buttom" onClick="javascript:window.close();">
9: 页面定时跳转
<meta http-equiv="refresh" content="10;url=http://61.136.146.163/WaterInf/report/rptmy.htm"> 定时跳转页面
10:自动跳转
<script language='javascript'>
setTimeout("{location.href='*.jsp'}",5000);
</script>)
11:自动关闭
<script LANGUAGE="JavaScript">
setTimeout('window.close();', 60000);
</script>
window.open ('page.html', 'newwindow', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')