我想在浏览器读取网页时识别不同的分辨率载入不同的图片,请问应


我的网页中的图片是这样命名的:不同分辨率的同一图片,800*600分辨率的命名为a_800.jpg,1024*768分辨率的命名为a_1024.jpg;其他b_800.jpg,b_1024.jpg......如此类推,试问怎样通过变量传递在浏览器读取网页时识别不同的分辨率载入不同的图片,比较快地实现这个功能,希望有详细的范例代码,100分一定给。
问题点数: 100、回复次数: 10
1楼  jiangsheng   ( 蒋晟.Net[MVP])  回复于  2001-10-09 18:09:11  得分 0

windows.screen  
   
  screen   Object  
   
  --------------------------------------------------------------------------------  
   
  Contains   information   about   the   client's   screen   and   rendering   capabilities.    
   
  Remarks  
   
  This   object   is   available   in   script   as   of   Microsoft®   Internet   Explorer   4.0.  
   
  Members  
   
  AllAttributesPropertiesMethodsEventsCollectionsBehaviorsFilters       Description    
  availHeight     Retrieves   the   height   of   the   working   area   of   the   system's   screen,   excluding   the   Microsoft®   Windows®   taskbar.    
  availWidth     Retrieves   the   width   of   the   working   area   of   the   system's   screen,   excluding   the   Microsoft®   Windows®   taskbar.    
  bufferDepth     Sets   or   retrieves   the   number   of   bits   per   pixel   used   for   colors   in   the   off-screen   bitmap   buffer.    
  colorDepth     Retrieves   the   number   of   bits   per   pixel   used   for   colors   on   the   destination   device   or   buffer.    
  fontSmoothingEnabled     Retrieves   whether   the   user   has   enabled   font   smoothing   in   the   Display   control   panel.    
  height     Retrieves   the   vertical   resolution   of   the   screen.    
  updateInterval     Sets   or   retrieves   the   update   interval   for   the   screen.    
  width     Retrieves   the   horizontal   resolution   of   the   screen.    
   
  *   denotes   an   extension   to   the   W3C   DOM.  
  Standards   Information  
  The   object   is   defined   in   HTML   .  
   
  Applies   To  
  window   object  
 
2楼  Jneu   ( 沧海桑田)  回复于  2001-10-09 18:10:35  得分 0

UP
3楼  forgot2000   ( 忘记2000年)  回复于  2001-10-09 19:45:43  得分 0

我知道识别分辨率的代码,分别取出screen.width和screen.height即可,但我问的不是这个问题呀,我指的是我得到screen.width=800时,载入a_800.jpg图片,screen.width=1024时,载入a_1024.jpg图片,我问的是这个问题,楼上的仁兄请看准我的问题。
4楼  forgot2000   ( 忘记2000年)  回复于  2001-10-09 20:09:20  得分 0

关注。
5楼  forgot2000   ( 忘记2000年)  回复于  2001-10-09 21:07:16  得分 0

关注。
6楼  karma   ( 无为MS MVP)  回复于  2001-10-09 21:18:39  得分  100

<script   language="javascript">  
  function   init()  
  {  
      var   suffix   =   window.screen.width;  
      var   imgs   =   document.all.images;  
      for   (var   i=0;   i   <   imgs.length;   i++)  
      {  
            if   (imgs[i].id   !=   ""   &&   imgs[i].src   ==   "")  
            {  
                    imgs[i].src   =   imgs[i].id   +   "_"+   suffix   +   ".jpg";  
            }  
      }  
  }  
  </script>  
   
  <body   οnlοad="init()">  
  <img   id="a"   src="">  
  <img   id="b"   src="">  
  </body>  
 
7楼  forgot2000   ( 忘记2000年)  回复于  2001-10-10 08:55:07  得分 0

楼上的代码不行。关注。
8楼  karma   ( 无为MS MVP)  回复于  2001-10-10 09:00:16  得分 0

var   imgs   =   document.all.images;  
  ===>  
  var   imgs   =   document.images;
9楼  karma   ( 无为MS MVP)  回复于  2001-10-10 09:05:05  得分 0

<script   language="javascript">  
  function   init()  
  {  
      var   suffix   =   window.screen.width;  
      var   imgs   =   document.images;  
      for   (var   i=0;   i   <   imgs.length;   i++)  
      {  
          if   (imgs[i].id   !=   "")  
          {  
                  imgs[i].src   =   imgs[i].id   +   "_"+   suffix   +   ".jpg";  
          }  
      }  
  }  
  </script>  
   
  <body   οnlοad="init()">  
  <img   id="a"   src="">  
  <img   id="b"   src="">  
  </body>  
 
10楼  forgot2000   ( 忘记2000年)  回复于  2001-10-10 11:28:40  得分 0

呵呵,无为,其实我知道你的代码是正确的,只是有一点小问题,我说你的代码不行时是想让你自己发现,document.all没有images属性,你已经发现,你最后改的代码只是判别imgs[i].id我认为不好,可以把原来的  
  if   (imgs[i].id   !=   ""   &&   imgs[i].src   ==   "")保留下来,把<img   id="a"   src="">中的src=""去掉即可,
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值