我想在一张图片右边40px处放一个div,我的做法是这样的:
document.watch.style.pixelleft=document.img.style.width+40
其中watch是那个div,而img是图片,这个表达式放入函数后不能正常运行,不知是哪里错了。
另外,在如何在html中的div的style处直接设置这个表达式呢?麻烦!麻烦!

解决方案 »

  1.   

    把图片放到一个div里边去。然后 div使用float左/右布局<div>
      <div style="float:left;"><img src="QQ截图未命名.png" style="width:200px;height:200px;"/></div>
      <div style="float:left;margin-left:40px;">sadfasdf</div>
      <DIV style="clear:both;"></DIV>
    </div>
      

  2.   


      document.getElementById('watch').style.position = 'absolute';
      document.getElementById('watch').style.top = document.getElementById('img').style.top;
      document.getElementById('watch').style.left = (parseInt(document.getElemnetById('img').clientWidth) + 40).toString() + 'px';
      

  3.   

    document.img.style.width本身是带px的,转换成整形
    parseFloat(document.img.style.width)
      

  4.   

    document.getElementById()获取对象再赋样式