简体   繁体   English

为什么我们不能直接在javascript中使用html输入标签?

[英]Why can't we use html input tags in javascript directly?

我是 javascript 的初学者。我试图在 .js 文件中的 javascipt 代码中编写一个 html 输入标签。它没有显示任何输出,但是当我在 document.write(" ") 中编写输入标签时,它显示了输出.为什么我们不能在javascript代码中直接使用这些html输入标签?

In the analogy of a body, think about HTML as the bones.以身体为例,将 HTML 视为骨骼。 It is only there to provide structure.它只是在那里提供结构。 JavaScript are the muscles, used to provide functionality and make the website dynamic and CSS is the skin, wrapping everything up in an appealing way. JavaScript 是肌肉,用于提供功能并使网站动态化,CSS 是皮肤,以吸引人的方式包装一切。

JavaScript is used to manipulate the DOM structure of a webpage. JavaScript 用于操作网页的 DOM 结构。 More on the DOM here https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction有关 DOM 的更多信息,请访问https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction

Accessing the DOM allows you to change your HTML dynamically.访问 DOM 允许您动态更改 HTML。

Firstly, you should always remember that HTML is a markup language, which means it is intended to provide a structural appearance to your content.首先,您应该始终记住 HTML 是一种标记语言,这意味着它旨在为您的内容提供结构化外观。 Then, JavaScript is for scripting, which means you can have added functionality to your content.然后,JavaScript 用于编写脚本,这意味着您可以为内容添加功能。

Now, I think you can understand why you were not able to use the HTML tags in JavaScripts.现在,我想您可以理解为什么不能在 JavaScript 中使用 HTML 标签了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM