在HTML中使用内联事件处理程序是不好的做法吗? [英] Is it bad practice to use inline event handlers in HTML?

查看:167
本文介绍了在HTML中使用内联事件处理程序是不好的做法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用内嵌JavaScript事件处理程序是不是很糟糕,或者是不是很好?



在我打算使用它的页面上,我只打算使用一个事件处理程序,所以在这种情况下使用内联事件处理程序是可以接受的,或者我应该在< script>中写入事件处理程序的代码。标签?

解决方案

如果您的关注是您的标记和维护的可读性,那么它的不良做法,特别是在更大的范围内相当凌乱 - 还要记住,内联JS永远不会像外部js文件一样被缓存,所以你对性能有一定的影响,特别是如果你滥用它



阅读本文以获得更多见解: http://robertnyman.com/2008/11/20/why-inline-css-and-javascript-code-is-such-a-bad-thing/


Is it bad to use inline JavaScript event handlers, or is that fine?

On the page I plan to use it on, I'm only going to use an event handler once, so is it acceptable to use an inline event handler in this case, or shall I write the code for the event handler within <script> tags?

解决方案

Its bad practice if your concern is readability in your mark-up and maintenance, especially on a larger scale it can get quite messy - also keep in mind the inline JS will never be cached like an external js file would so you do suffer a bit in regards to performance especially if you abuse it

Read this article for more insight: http://robertnyman.com/2008/11/20/why-inline-css-and-javascript-code-is-such-a-bad-thing/

这篇关于在HTML中使用内联事件处理程序是不好的做法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆