JavaScript判断上传文件的大小
<form name="form1">
<input type="file" name="file1" onchange="checkimage
(value)">
</form>
<script language="javascript">
var img=null;
function checkimage(name){
if(/^.+\.(gif|jpg|png)$/i.test(name))
{
if(img)img.removeNode(true);
img=document.createElement("img");
img.style.position="absolute";
img.style.visibility="hidden";
img.attachEvent("onerror",oe);
img.attachEvent("onreadystatechange",orsc);
document.body.insertAdjacentElement("beforeend",img);
img.src=name;
}
else{oe()}
}
function oe(){
form1.reset();
alert("文件类型只能是<gif><jpg><png>!");
}
function orsc(){
if (img.fileSize>51200){
form1.reset();
alert("文件大小不能超过50K!");
}
}
</script>
相关文档:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Wanna tell her - interactive DHTML </title>
<meta http-equiv="imagetoolbar" content="no">
<style type="text/css">
html {
overflow: h ......
1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)><td>no</table> 可用于Table
2. <body onselectstart="return false"> 取消选取、防止复制
3. onpaste="return false" 不准粘贴
4. oncopy="return false;" oncut="return f ......
http://code.google.com/p/update-javascript-trim/
常见的写法为:
function trim(s){
return s.replace(/^\s+|\s+$/g, '');
}
优化后trim函数的代码如下:
function trim(str) {
str = str.replace(/^\s+/g, '');
for(var i = str.length - 1; i >= 0; i--){
if(!/^\s$/.test(str.substr(i,1) ......
1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)> <td>no </table> 可用于Table
2. <body onselectstart="return false"> 取消选取、防止复制
3. onpaste="return false" 不准粘贴
4. oncopy ......