0

对于横幅,我需要放置在同一页面上显示的图像。我作为开发人员真的很糟糕 - 所以,我用这种方式 - 但是,确实,它不起作用......

<!doctype html>
<html lang="fr">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <meta name="ad.size" content="width=300,height=600">
  <title>Stack</title>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
  <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
</head>
<body>
  <a id="clickThroughBtn" href="javascript:window.open(window.clickTag)">
  <div id="border">
    <div id="container">
      <div class="border2">
        <div id="logo_bg"></div>
        <div id="red_c" class="logo_element"></div>
        <div id="rays" class="logo_element"></div>
        <div class="logo"><img src="logo_fr.svg" alt="Cofidis" /></div>
        <div class="title">
          Test
          <div id="adaptive">
            <script>
              function getImgs(){
                var Adaptive = document.getElementsByID('thumb0').img;
                Adaptive[0].style.width="200px"; // Taille de l'image
                Adaptive[0].style.width="200px"; // Hauteur
              }
            </script>
          </div>
        </div>
      </div>
    </div>
    </a>
    <img id="thumb0" src="http://gmz2.zarbi.be/avatars/m/1/1116.jpg?1404045273.jpg" />
</html>

最重要的部分——

<!-- Adaptive -->
<div id="adaptive">
  <script>
    function getImgs(){
      var Adaptive = document.getElementsByID('thumb0').img;
      Adaptive[0].style.width="200px"; // Taille de l'image
      Adaptive[0].style.width="200px"; // Hauteur
    }
  </script>
</div>
<!-- Adaptive -->

谢谢大家 !卢多维奇

4

1 回答 1

0

你需要改变这个:

var Adaptive = document.getElementsByID('thumb0').img;
Adaptive[0].style.width="200px";                       // Taille de l'image
Adaptive[0].style.width="200px";                       // Hauteur

对此:

var Adaptive = document.getElementById('thumb0');
Adaptive.style.width="200px";                         // set image width
Adaptive.style.height="200px";                        // set image height

因为文档对象中没有这样的方法getElementsByID 。

此外,getElementById 返回单个元素。如果您需要获取多个对象,那么getElementsByNamegetElementsByClassNamegetElementsByTagName将为您工作。

于 2015-09-21T10:43:29.980 回答