js常用技巧1
1.js判断上传是否为图片格式var ImageFileExtend = ".gif,.png,.jpg,.ico,.bmp"; var file = document.getElementById("uploadpictureformat");if(file.value.length>0) {var fileExtend=file.value.substring(file.value.lastIndexOf('.')).toLowerCase(); //判断后缀 if(ImageFileExtend.indexOf(fileExtend)>-1) { //显示预览 document.getElementById("uploadpictureformatinfo").style.display="none"; } else { document.getElementById("uploadpictureformatinfo").style.display=""; return false; } }<input id="uploadpictureformat" class="bt" type="file" size="24" name="file" /><span id="uploadpictureformatinfo" style="display: none;color:red"><fmt:message key="jsp.general.upload.picture.format.info" /></span>
2.JavaScript对话框按钮
alert("alert");
confirm("confirm");
var name=prompt("prompt","");
3.javascript页面执行返回、刷新、前进操作的代码:
JavaScript让页面返回的代码:
<a href="Javascript:history.go(-1)">返回上一页</a>
<a href="Javascript:history.back()">返回上一页</a>
<a href="Javascript:window.history.go(-1)">返回上一页</a>
<a href="Javascript:window.history.back()">返回上一页</a>
JavaScript让页面刷新的代码:
<a href="Javascript:history.go()">刷新</a>
<a href="Javascript:history.go(0)">刷新</a>
<a href="Javascript:window.history.go(0)">刷新</a>
JavaScript让页面前进的代码:
<a href="Javascript:history.go(1)">前进</a>
<a href="Javascript:window.history.go(1)">刷新</a>
javascript - 页面返回并刷新
<script language='javascript'>
window.history.go(-2);
window.history.go(0);
</script>
4.
5.
<body oncontextmenu="window.event.returnvalue=false" >
//将彻底屏蔽鼠标右键
<body onselectstart="return false">
//取消选取、防止复制
onpaste="return false"
//不准粘贴
oncopy="return false;" oncut="return false;"
//防止复制
6.
function document.oncontextmenu(){event.returnValue=false;}
//屏蔽鼠标右键
function document.onkeydown()
{
if (event.keyCode==116){
//屏蔽 F5 刷新键
event.keyCode=0;
event.returnValue=false;
}
}
7.
window.top.location="...."可以跳出原来的框架,刷新父框架
targit="_top"
页:
[1]