首页javascriptattributeJavascript DOM - 如何通过设置src属性来加载图像

Javascript DOM - 如何通过设置src属性来加载图像

我们想知道如何通过设置src属性来加载图像。

<!DOCTYPE html>
<html>
<head>
<script
  src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
</head>
<body>
  <img class="a" />
  <script>
    $(".a").attr('src',"http://www.w3cschool.cn/style/download.png");
    console.log($(".a").length);
    </script>
</body>
</html>