if(screen.width==800)
img1.src='1.gif'
else
img1.src='2.gif'

解决方案 »

  1.   

    if(screen.width==640){code}  //640*800
    if(screen.width==800){code}  //800*600
    if(screen.width==1024){code} //1024*768
      

  2.   

    思路:将要调用分辨率的图片命名为a_640.gif[jpg...],a_800.gif
    页面初始用一套方案,不同分辨率掉不同图片设定方案。
    <script>
    var imgs=document.images;//所有<img>集合;
    var defaultWidth="640";//图片默认值
    var sImgSrc;
    function getWidth(){
     var w=screen.width;
     if(w<640) w=640;
     else if(w>1024) w=1024;
     w.toString();
     return w;
    }var newWidth=getWidth();//取得介于640-1024间的图片修饰字符串for(var i=0;i<imgs.length;i++){
     sImgSrc=imgs[i].src;
     imgs[i].src=sImgSrc.replace(defaultWidth,newWidth);//替换全部买足条件的img
    }
    </script>
    若是不想该图片文件名。
    1,创建img数组
    2,
    我靠,想想都烦,不写了!
      

  3.   

    其实如果是矢量图(swf)还可以这么做,其它类型的图片这样做就得不偿失了.
      

  4.   

    to  exwind(亦然) :
    未测试,还成功率90%?to fason(阿信):
    我用你的方法,写了一个Function,然后在body onload事件中调用
    可是图片在body里的一个表格的单元格里,进入页面时,就弹出img1未定义,可是我已经定义这个图片的id为img1了,怎么解决?另外怎么能同时也改变表格单元格的高度,以适应不同的图片?
      

  5.   

    if(screen.width==640){location.href="1.htm"}  //640*800
    if(screen.width==800){location.href="2.htm"} //800*600
    if(screen.width==1024){location.href="3.htm"} //1024*768
      

  6.   

    使用this.location=1.htm 也可以,我就这样实现的:)