在HTML中使用内联事件处理程序是不好的做法吗?

时间:2021-08-31 03:27:33

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

使用内联JavaScript事件处理程序是不是很糟糕,还是那么好?

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?

在我计划使用它的页面上,我只会使用一次事件处理程序,所以在这种情况下使用内联事件处理程序是可以接受的,还是应该在

1 个解决方案

#1


9  

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

如果您的关注是标记和维护的可读性,那么这是一种不好的做法,特别是在更大规模上它可能会变得非常混乱 - 同时请记住,内联JS永远不会像外部js文件一样缓存,所以你会受到一些影响关于表现,特别是如果你滥用它

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

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

#1


9  

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

如果您的关注是标记和维护的可读性,那么这是一种不好的做法,特别是在更大规模上它可能会变得非常混乱 - 同时请记住,内联JS永远不会像外部js文件一样缓存,所以你会受到一些影响关于表现,特别是如果你滥用它

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

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