javascript 用途_这就是JavaScript的用途

javascript 用途

There are a number of different places where JavaScript can be used but the most common place to use it is in a web page. In fact, for most people using JavaScript, in a web page is the only place where they use it.

在许多不同的地方都可以使用JavaScript,但是最常使用的地方是网页。 实际上,对于大多数使用JavaScript的人来说 ,网页是他们使用JavaScript的唯一场所。

网站的三种语言 ( The Three Languages of a Website )

The first requirement of a web page is to define the content of the web page. This is done using a markup language that defines what each of the component parts of the content are. The language that is normally used to markup the content is HTML although XHTML can also be used if you do not require the pages to work in Internet Explorer.

网页的首要要求是定义网页的内容 。 这是使用一种标记语言完成的,该标记语言定义了内容的每个组成部分。 通常,用于标记内容的语言是HTML,尽管如果您不需要页面在Internet Explorer中工作,也可以使用XHTML。

HTML Code
Hamza TArkkol / Getty Images
Hamza TArkkol /盖蒂图片社

The HTML defines what the content is. When written properly no attempt is made to define how that content is supposed to look. After all, the content will need to look different depending on what device is being used to access it. Mobile devices generally have smaller screens than computers. Printed copies of the content will have a fixed width and may not require all the navigation be included. For people listening to the page, it will be how the page is read rather than how it looks that needs to be defined.

HTML定义了内容。 正确编写后,不会尝试定义该内容的外观。 毕竟,内容将根据使用哪种设备访问它而看起来有所不同。 移动设备的屏幕通常比计算机小。 内容的打印副本将具有固定的宽度,并且可能不需要包括所有导航。 对于正在听页面的人来说,将是如何读取页面而不是需要如何定义页面。

The appearance of a web page is defined using Cascading Style Sheets that specify which media the specific commands apply to, so the content formats appropriately for the device.

网页的外观是使用级联样式表定义的,该样式表指定了特定命令适用于哪种媒体,因此内容格式适合于设备。

Using just these two languages you can create static web pages that will be accessible regardless of which device is used to access the page. These static pages can interact with your visitor through the use of forms. After a form is filled out and submitted, a request is sent back to the server where a new static web page is constructed and eventually downloaded into the browser.

仅使用这两种语言,您就可以创建静态网页,无论使用哪种设备访问该网页,都可以访问它们。 这些静态页面可以通过使用表单与访问者进行交互。 填写并提交表单后,将请求发送回服务器,在服务器上构造一个新的静态网页,并最终将其下载到浏览器中。

The big disadvantage of web pages like this is that the only way that your visitor has of interacting with the page is by filling out the form and waiting for a new page to load.

此类网页的最大缺点是,访问者与该页面进行交互的唯一方法是填写表单并等待新页面加载。

为动态页面添加JavaScript ( Add JavaScript for Dynamic Pages )

JavaScript translates your static page into one that can interact with your visitors without them needing to wait for a new page to load every time they make a request. JavaScript adds behavior to the web page where the page responds to actions without needing to load a new page to process the request.

JavaScript将您的静态页面转换为可以与访问者进行交互的页面,而无需他们在每次发出请求时都等待新页面加载。 JavaScript将行为添加到网页中,网页在该网页中对动作做出响应,而无需加载新页面来处理请求。

No longer does your visitor need to fill out an entire form and submit it in order to be told that they made a typo in the first field and need to enter it all again. With JavaScript, you can validate each of the fields as they enter it and provide immediate feedback when they err.

您的访客不再需要填写完整的表单并提交表格,而是被告知他们在第一个字段中输入了错字,并且无需再次输入。 使用JavaScript,您可以在每个字段输入时对其进行验证,并在出现错误时立即提供反馈。

Close up of internet security form
Tetra Images / Getty Images
Tetra图片/盖蒂图片社

JavaScript also allows your page to be interactive in other ways that do not involve forms at all. You can add animations into the page that either attract attention to a specific part of the page or which make the page easier to use.You can provide responses within the web page to various actions that your visitor takes so as to avoid the need to load new web pages to respond. You can even have the JavaScript load new images, objects, or scripts into the web page without needing to reload the entire page. There is even a way for JavaScript to pass requests back to the server and handle responses from the server without the need for loading new pages.

JavaScript还允许您的页面以完全不涉及表单的其他方式进行交互。 您可以在页面中添加动画,以吸引人们注意页面的特定部分或使页面更易于使用。您可以在网页中提供对访问者采取的各种操作的响应,从而避免加载新的网页来回应。 您甚至可以让JavaScript将新的图像,对象或脚本加载到网页中,而无需重新加载整个页面。 JavaScript甚至可以通过一种方式将请求传递回服务器并处理来自服务器的响应,而无需加载新页面。

Incorporating JavaScript into a web page allows you to improve your visitor's experience by converting it from a static page into one that can interact with them. One important thing to remember though is that not everyone visiting your page will have JavaScript and so your page will still need to work for those who don't have JavaScript. Use JavaScript to make your page work better for those who have it.

将JavaScript集成到网页中,可以将访问者从静态页面转换为可以与他们互动的页面 ,从而改善访问者的体验。 但要记住的一件事是,并非所有访问您页面的人都将使用JavaScript,因此您的页面仍将需要为那些没有JavaScript的用户使用。 使用JavaScript使您的页面更好地适合拥有它的人。

翻译自: https://www.thoughtco.com/what-is-javascript-used-for-2037679

javascript 用途

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值