跪求大神。为什么JS显示图片的缩略图在.HTML中能运行,在.ASPX中不能?(我现在是菜鸟) 10
跪求大神。为什么JS显示图片的缩略图在.HTML中能运行,在.ASPX中不能?(我现在是菜鸟)我直接复制代码过去,JS是能用的,但是显示不了图片。<scriptlangu...
跪求大神。为什么JS显示图片的缩略图在.HTML中能运行,在.ASPX中不能?(我现在是菜鸟)
我直接复制代码过去,JS是能用的,但是显示不了图片。
<script language="javascript" type="text/javascript">
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 120/80){
if(image.width>120){
ImgD.width=120;
ImgD.height=(image.height*120)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>80){
ImgD.height=80;
ImgD.width=(image.width*80)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
/**//*else{
ImgD.src="";
ImgD.alt=""
}*/
}
function FileChange(Value)
{
flag=false;
document.all.uploadimage.width=10;
document.all.uploadimage.height=10;
document.all.uploadimage.alt="";
document.all.uploadimage.src=Value;
}
function BeforeUpLoad(){
if(flag) alert("OK");else alert("FAIL");
}
</script>
<INPUT style="WIDTH: 143px; HEIGHT: 18px" type=file size=8 name=pic onchange="javascript:FileChange(this.value);">
<IMG id=uploadimage height=10 width=10 src="" onload="javascript:DrawImage(this);" ><BR>
<Button onclick="javascript:BeforeUpLoad();">提交</Button> 展开
我直接复制代码过去,JS是能用的,但是显示不了图片。
<script language="javascript" type="text/javascript">
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 120/80){
if(image.width>120){
ImgD.width=120;
ImgD.height=(image.height*120)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>80){
ImgD.height=80;
ImgD.width=(image.width*80)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
/**//*else{
ImgD.src="";
ImgD.alt=""
}*/
}
function FileChange(Value)
{
flag=false;
document.all.uploadimage.width=10;
document.all.uploadimage.height=10;
document.all.uploadimage.alt="";
document.all.uploadimage.src=Value;
}
function BeforeUpLoad(){
if(flag) alert("OK");else alert("FAIL");
}
</script>
<INPUT style="WIDTH: 143px; HEIGHT: 18px" type=file size=8 name=pic onchange="javascript:FileChange(this.value);">
<IMG id=uploadimage height=10 width=10 src="" onload="javascript:DrawImage(this);" ><BR>
<Button onclick="javascript:BeforeUpLoad();">提交</Button> 展开
3个回答
展开全部
估计跟你的路径有关系。。你不妨先看下你图片的路径。。估计都会成为C:\fakepath\...jpg
如果是这样的话。。建议你用我这个。。然后把你要的照片传到站内。。在进行显示处理。。。
<html>
<head>
<script language="javascript" type="text/javascript">
var flag = false;
function $(e) {return document.getElementById(e);}
function DrawImage(ImgD) {
var h = $("uploadimage").height;
var w = $("uploadimage").width;
if (w > 0 && h > 0) {
flag = true;
if (w / h >= 120 / 80) {
if (w > 120) {
$("uploadimage").width = 120;
$("uploadimage").height = (h * 120) / w;
} else {
$("uploadimage").width = w;
$("uploadimage").height = h;
}
$("uploadimage").alt = w + "×" + h;
}
else {
if (h > 80) {
$("uploadimage").height = 80;
$("uploadimage").width = (w * 80) / h;
} else {
$("uploadimage").width = w;
$("uploadimage").height = h;
}
$("uploadimage").alt = w + "×" + h;
}
}
}
function FileChange(Value) {
flag = false;
document.all.uploadimage.alt = "";
var pos = Value.lastIndexOf("\\") + 1;
Value = Value.substring(pos, Value.length);
document.all.uploadimage.src = "images/" + Value;
}
function BeforeUpLoad() {
if (flag) alert("OK"); else alert("FAIL");
}
</script>
</head>
<body>
<INPUT style="WIDTH: 143px; HEIGHT: 18px" type=file size=8 name=pic onchange="javascript:FileChange(this.value);">
<IMG id=uploadimage src="" onload="javascript:DrawImage(this);" ><BR>
<Button onclick="javascript:BeforeUpLoad();">提交</Button>
</body>
</html>
如果是这样的话。。建议你用我这个。。然后把你要的照片传到站内。。在进行显示处理。。。
<html>
<head>
<script language="javascript" type="text/javascript">
var flag = false;
function $(e) {return document.getElementById(e);}
function DrawImage(ImgD) {
var h = $("uploadimage").height;
var w = $("uploadimage").width;
if (w > 0 && h > 0) {
flag = true;
if (w / h >= 120 / 80) {
if (w > 120) {
$("uploadimage").width = 120;
$("uploadimage").height = (h * 120) / w;
} else {
$("uploadimage").width = w;
$("uploadimage").height = h;
}
$("uploadimage").alt = w + "×" + h;
}
else {
if (h > 80) {
$("uploadimage").height = 80;
$("uploadimage").width = (w * 80) / h;
} else {
$("uploadimage").width = w;
$("uploadimage").height = h;
}
$("uploadimage").alt = w + "×" + h;
}
}
}
function FileChange(Value) {
flag = false;
document.all.uploadimage.alt = "";
var pos = Value.lastIndexOf("\\") + 1;
Value = Value.substring(pos, Value.length);
document.all.uploadimage.src = "images/" + Value;
}
function BeforeUpLoad() {
if (flag) alert("OK"); else alert("FAIL");
}
</script>
</head>
<body>
<INPUT style="WIDTH: 143px; HEIGHT: 18px" type=file size=8 name=pic onchange="javascript:FileChange(this.value);">
<IMG id=uploadimage src="" onload="javascript:DrawImage(this);" ><BR>
<Button onclick="javascript:BeforeUpLoad();">提交</Button>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询