简体   繁体   中英

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. 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 is used to manipulate the DOM structure of a webpage. More on the DOM here https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction

Accessing the DOM allows you to change your HTML dynamically.

Firstly, you should always remember that HTML is a markup language, which means it is intended to provide a structural appearance to your content. Then, JavaScript is for scripting, which means you can have added functionality to your content.

Now, I think you can understand why you were not able to use the HTML tags in JavaScripts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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