<div id="div1">111111111</div> <button onclick="handleClick()">OK</button> <script type="text/javascript" charset="utf-8"> const div1 = document.querySelector('#div1'); const observe = new MutationObserver((mutations) => { console.log('hhhh', mutations) }).observe(div1, { attributes: true }) function handleClick() { div1.setAttribute('style', 'color: red') div1.setAttribute('data-name', 'abc') } </script>
标签:const,元素,setAttribute,mutations,observe,监听,div1,属性 From: https://www.cnblogs.com/chicidol/p/17205546.html