HTML事件属性和使用HTML DOM分配事件之间有什么区别? [英] What is the difference between HTML Event Attributes and Assign Events Using the HTML DOM?
本文介绍了HTML事件属性和使用HTML DOM分配事件之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HTML事件属性:
<button onclick="displayDate()">Try it</button>
使用HTML DOM分配事件:
Assign Events Using the HTML DOM:
<script>
document.getElementById("myBtn").onclick = function(){ displayDate() };
</script>
这两者之间有什么区别?使用(使用HTML DOM分配事件)有什么好处?
What is the difference between these two ? Any advantages in using (Assign Events Using the HTML DOM) ?
谢谢
推荐答案
优点是您不会将js代码与html混淆,它允许您分隔编程层。这使您的代码更整洁,不易出现错误。
一种符合Web访问规则和良好编程基础的做法。
The advantage is you don't mess js code with html, it permits you to separate programming layers. This renders your code cleaner and less prone to bugs. A practice that complies with web accessibility rules and good programming foundations.
这篇关于HTML事件属性和使用HTML DOM分配事件之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文