<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MyHtml.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=gbk">
<script type="text/javascript">
function clearFilename(filename){
var imgvalue=document.getElementById("uploadphoto").value;
var imgsrc=document.getElementById("jcrop_target");
imgsrc.src=filename;
checkImgWH();
}
function checkImgWH(){
//alert('1');
var imgobj=document.getElementById("jcrop_target");
var imgheight=480;
var imgwidth=640;
//alert(""+imgobj[0].src+" 该图片的实际宽="+imgobj[0].width+" 高="+imgobj[0].height+" 需要更改吗");
if(imgobj.width!=imgwidth||imgobj.height!=imgheight){
alert("图片像素要求宽:640 高:480 该图片的宽="+imgobj.width+" 高="+imgobj.height+" 请重新拍照");
//if(confirm("图片像素要求宽:"+imgwidth+" 高:"+imgheight+" 该图片的实际宽="+imgobj[0].width+" 高="+imgobj[0].height+" 需要更改吗")){
//document.getElementById("savebutton").disabled=true;
//}
}
else{
// document.getElementById("savebutton").disabled=false;
}
}
</script>
</head>
<body>
<input class="mywidget" type="file" name="uploadphoto" id="uploadphoto" size="50"
onchange="clearFilename(this.value);" />
<img src="C:\vehdigital1\xiyan.jpg" id="jcrop_target" name="jcrop_target" />
</body>
</html>
<html>
<head>
<title>MyHtml.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=gbk">
<script type="text/javascript">
function clearFilename(filename){
var imgvalue=document.getElementById("uploadphoto").value;
var imgsrc=document.getElementById("jcrop_target");
imgsrc.src=filename;
checkImgWH();
}
function checkImgWH(){
//alert('1');
var imgobj=document.getElementById("jcrop_target");
var imgheight=480;
var imgwidth=640;
//alert(""+imgobj[0].src+" 该图片的实际宽="+imgobj[0].width+" 高="+imgobj[0].height+" 需要更改吗");
if(imgobj.width!=imgwidth||imgobj.height!=imgheight){
alert("图片像素要求宽:640 高:480 该图片的宽="+imgobj.width+" 高="+imgobj.height+" 请重新拍照");
//if(confirm("图片像素要求宽:"+imgwidth+" 高:"+imgheight+" 该图片的实际宽="+imgobj[0].width+" 高="+imgobj[0].height+" 需要更改吗")){
//document.getElementById("savebutton").disabled=true;
//}
}
else{
// document.getElementById("savebutton").disabled=false;
}
}
</script>
</head>
<body>
<input class="mywidget" type="file" name="uploadphoto" id="uploadphoto" size="50"
onchange="clearFilename(this.value);" />
<img src="C:\vehdigital1\xiyan.jpg" id="jcrop_target" name="jcrop_target" />
</body>
</html>
onchange="clearFilename(this.value);" />
type="file"可以跟type=submit的效果是一样的,点击以后都是提交表单。
<html>
<head>
<title>MyHtml.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=gbk">
<script type="text/javascript">
function clearFilename(filename){var imgsrc=document.getElementById("jcrop_target");
imgsrc.src=filename;alert(filename);alert(imgsrc.width);
//checkImgWH();
}
function checkImgWH(){
//alert('1');
var imgobj=document.getElementById("jcrop_target");
var imgheight=480;
var imgwidth=640;//alert(""+imgobj[0].src+" 该图片的实际宽="+imgobj[0].width+" 高="+imgobj[0].height+" 需要更改吗");
if(imgobj.width!=imgwidth||imgobj.height!=imgheight){
alert("图片像素要求宽:640 高:480 该图片的宽="+imgobj.width+" 高="+imgobj.height+" 请重新拍照");
//if(confirm("图片像素要求宽:"+imgwidth+" 高:"+imgheight+" 该图片的实际宽="+imgobj[0].width+" 高="+imgobj[0].height+" 需要更改吗")){
//document.getElementById("savebutton").disabled=true;
//}
}
else{
// document.getElementById("savebutton").disabled=false;
}
}
</script>
</head>
<body>
<input class="mywidget" type="file" name="uploadphoto" id="uploadphoto" size="50"
onchange="clearFilename(this.value);" />
<img src="C:\vehdigital1\xiyan.jpg" id="jcrop_target" name="jcrop_target" />
</body>
</html>
你这样试一下,感觉是速度太快了,所以还是替换前的图片宽度
用img的加载事件来 输出就是最新的图片长宽了
onreadstatechange为complete