代码示例:(标识:jsck_element_getattribute_3)
<!DOCTYPE html>
<html>
<body>

<h1>Element 对象</h1>

<h2>getAttribute() 方法</h2>

<button id="myButton" onclick="myFunction()">按钮</button>

<p>按钮的 onclick 属性的值是:</p>

<p id="demo"></p>

<script>
const myButton = document.getElementById("myButton"); 
let text = myButton.getAttribute("onclick");
document.getElementById("demo").innerHTML = text;
</script>

</body>
</html>
运行结果: