【www.gdgbn.com--js教程】
<script>
function toi_upimg()
{
var form = document.dform;
var isrc = form.ifile.value;
var pos = isrc.lastindexof(".");
var img = new image();// on load
img.onload = function () {
var width = img.width;
var height = img.height;
img.onload = "";
if (width > 480 || height > 320)
{
// => 480*360
var ratio1 = 320/width;
var ratio2 = 240/height;
if (ratio1 > ratio2)
{
width = parseint(ratio2 * width);
height = 240;
}
else
{
width = 320;
height = parseint(ratio1 * height);
}
alert("注意:图片过大, 系统自动进行了一些调整");
}
toi_img.src = img.src;
toi_img.width = width;
toi_img.height = height;
form.picwidth.value = width;
form.picheight.value = height;
form.mserver.value = "no";
form.xpost.value = "0";
form.ypost.value = "0";
form.xposy.value = "0";
form.yposy.value = "0";
form.xposa.value = "0";
form.yposa.value = "0";
if (form.title.value == "")
{
var pos2 = isrc.lastindexof("");
form.title.value = isrc.substring(pos2+1,pos);
}
toi_update();
delete img;
};// on error
img.onerror = function () {
img.onerror = "";
alert("注意:您刚刚试图上载的一个文件似乎不是合法图片");
delete img;
};// store the source address
if (navigator.appversion.indexof("msie 7") >= 0)
{
document.getelementbyid("filterimage").filters.item("dximagetransform.microsoft.alphaimageloader").src = isrc;
img.src = document.getelementbyid("filterimage").filters.item("dximagetransform.microsoft.alphaimageloader").src;
}
else
{
img.src = isrc;
}
}
</script>