获取元素内属性值

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<a href="https://www.baidu.com" title="百度一下" id="link" >百度一下</a>
<img src="https://xn--xu0a.cn/api/dn" alt="acg图片" class="pic" id="pic">



    <script>

var link = document.getElementById('link');
var pic = document.getElementById('pic');
console.log(link.href);        
console.log(link.title);
console.log(link.id);
console.log(pic.src);
console.log(pic.alt);
console.log(pic.className);

</script>
</body>
</html>

2023-07-13T08:04:55.png

更改指定属性值

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<a href="https://www.baidu.com" title="百度一下" id="link" >百度一下</a>
<img src="https://xn--xu0a.cn/api/dn" alt="acg图片" class="pic" id="pic">



    <script>

var link = document.getElementById('link');
var pic = document.getElementById('pic');

pic.src = "https://xn--xu0a.cn/api/sj";

</script>
</body>
</html>

2023-07-13T08:07:46.png