什么是内联 JavaScript?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19618571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 16:11:27  来源:igfitidea点击:

What is inline javascript?

javascriptjqueryhtml

提问by helloworld

Me and my programmer has 2 different views for what "Inline JavaScript" is.

我和我的程序员对“内联 JavaScript”有两种不同的看法。

  1. I said inline JavaScript means JavaScript placed directly in the HTML file, without in a .JS file.

  2. My programmer means inline JavaScript is JavaScript on 1 line, and like <button onclick="alert('test')">

  1. 我说内联 JavaScript 意味着 JavaScript 直接放在 HTML 文件中,而不是放在 .JS 文件中。

  2. 我的程序员的意思是内联 JavaScript 是 1 行的 JavaScript,并且喜欢 <button onclick="alert('test')">

I give him right in, that inline JavaScript also is "onclick='alert(...)"because it again is like my solution #1, all JavaScript loaded in HTML and not in JS.

我直接告诉他,内联 JavaScript 也是"onclick='alert(...)"因为它就像我的解决方案 #1,所有 JavaScript 都加载在 HTML 中而不是 JS 中。

Who's right?

谁是对的?

We have a HTML file, and there is <script>....</script>JavaScript in the bottom, that is inline javascript, right?

我们有一个 HTML 文件,<script>....</script>底部有JavaScript,也就是内联 javascript,对吧?

回答by Niet the Dark Absol

A scripttag without a src(ie. with code directly in the HTML document) is referred to as an inline script.

script没有 a的标签src(即直接在 HTML 文档中带有代码)被称为内联脚本。

An onclick="..."attribute is called an inline event handler.

一个onclick="..."属性被称为内联事件处理程序。

回答by T.J. Crowder

I've heard the term used for both of those, I don't think either of you is "wrong." I'd say I've heard it used morefor #1 than for #2. Most terms I've heard for #2 are more clunky, like "onxyz event handler" or "inline event handler" (thank you Niet the Dark Absolfor reminding me)or "DOM0 attribute event handler" or sometimes just "DOM0 handler."

我听说过用于这两个词的术语,我认为你们中的任何一个都没有“错”。我会说我听说它在#1 上比在#2 上使用得更多。我听说了#2多数条款都比较笨重,像“onxyz事件处理程序”或“内联事件处理程序” (谢谢你Niet的黑暗ABSOL提醒我或“DOM0属性事件处理程序”或有时仅称为“DOM0处理程序。 ”