<body>
? ? <button id="btn1">顯示圖片</button>
? ? <button id="btn2">更換圖片title</button>
? ? <button id="btn3">給圖片添加address屬性</button>
? ? <button id='btn4'>刪除圖片</button>
? ? <br>
? ? <img id="img" title="美麗的風(fēng)景">
? ? <script>
? ? ? ? //獲取圖片標(biāo)簽
? ? ? ? let img = document.querySelector('#img')
? ? ? ? //獲取按鈕并添加點(diǎn)擊事件
? ? ? ? document.querySelector('#btn1').onclick = function(){
? ? ? ? ? ? // 獲取 或 設(shè)置 標(biāo)簽的原生屬性秉氧,直接點(diǎn)
? ? ? ? ? ? img.src = 'https://img2.baidu.com/it/u=4265591365,617998863&fm=26&fmt=auto'
? ? ? ? }
? ? ? ? document.querySelector('#btn2').onclick = function(){
? ? ? ? ? ? img.title = '美麗的森林'
? ? ? ? }
? ? ? ? document.querySelector('#btn3').onclick = function(){
? ? ? ? ? ? // 獲取屬性的統(tǒng)一方法 getAttribute('屬性名稱')
? ? ? ? ? ? // 設(shè)置屬性的統(tǒng)一方法 setAttribute('屬性名稱','屬性值')
? ? ? ? ? ? img.setAttribute('address','地址在西班牙')
? ? ? ? ? ? // console.log(img.getAttribute('address'));
? ? ? ? }
? ? ? ? document.querySelector('#btn4').onclick = function() {
? ? ? ? ? ? img.remove()
? ? ? ? ? ? alert('圖片已刪除')
? ? ? ? }
? ? </script>
</body>