javascript使用_为什么使用JavaScript

javascript使用

Not everyone has JavaScript available in their web browser and a number of those who are using browsers where it is available have it turned off. It is therefore necessary that your web page be able to function properly for those people without using any JavaScript at all. Why then would you want to add JavaScript to a web page that already works without it?

并非每个人的Web浏览器中都有JavaScript,并且一些正在使用浏览器的人都将其关闭。 因此,有必要使您的网页能够完全适合那些人而无需使用任何JavaScript。 那为什么要在没有JavaScript的网页上添加JavaScript?

您可能想使用JavaScript的原因 ( Reasons Why You May Want to Use JavaScript )

There are several reasons for why you may want to use JavaScript on your web page even though the page is usable without the JavaScript. Most of the reasons relate to providing a friendlier experience for those of your visitors who do have JavaScript enabled. Here are a few examples of proper use of JavaScript to improve your visitor's experience.

即使网页在没有JavaScript的情况下仍可使用,您仍可能要在网页上使用JavaScript的原因有多种。 大多数原因与为那些启用了JavaScript的访问者提供更友好的体验有关。 以下是正确使用JavaScript来改善访问者体验的一些示例。

JavaScript非常适合表单 ( JavaScript Is Great for Forms )

Where you have forms on your web page that your visitor needs to fill out that form content will need to be validated before it can be processed. You will, of course, have server-side validation that validates the form after it is submitted and which reloads the form highlighting the errors if anything invalid has been entered or mandatory fields are missing. That requires a round trip to the server when the form is submitted to perform the validation and report the errors. We can speed up that process significantly by duplicating that validation using JavaScript and by attaching much of the JavaScript validation to the individual fields. That way the person filling out the form who has JavaScript enabled has immediate feedback if what they enter into a field is invalid instead of their filling out the whole form and submitting it and then having to wait for the next page to load to give them feedback. The form works both with and without JavaScript and provides more immediate feedback when it can.

网页上您有访客需要填写的表单的地方,需要先验证表单内容,然后才能进行处理。 当然,您将拥有服务器端验证,该验证将在提交表单后对其进行验证,并且如果输入的内容无效或必填字段缺失,则会重新加载该表单以突出显示错误。 提交表单以执行验证并报告错误时,这需要往返服务器。 通过使用JavaScript复制验证并将大量JavaScript验证附加到各个字段中,我们可以大大加快该过程。 这样,如果填写了启用了JavaScript的表单的人在字段中输入的内容无效,则会立即获得反馈,而不是填写整个表单并提交,然后必须等待下一页加载以提供反馈。 该表单可以使用JavaScript,也可以不使用JavaScript,并可以在可能的情况下提供更多即时反馈。

幻灯片放映 ( A Slideshow )

A slideshow consists of a number of images. In order for the slideshow to function without JavaScript the next and previous buttons that work the slideshow need to reload the entire web page substituting the new image. This will work but will be slow, particularly if the slideshow is only one small part of the page. We can use JavaScript to load and replace the images in the slideshow without needing to reload the rest of the web page and so make the slideshow operation much faster for those of our visitors with JavaScript enabled.

幻灯片由许多图像组成。 为了使幻灯片演示在不使用JavaScript的情况下运行,需要使用幻灯片的下一个和上一个按钮才能重新加载整个网页以替换新图像。 这会起作用,但是会很慢,特别是如果幻灯片只是页面的一小部分。 我们可以使用JavaScript来加载和替换幻灯片中的图像,而无需重新加载网页的其余部分,因此对于启用了JavaScript的访问者来说,幻灯片显示的操作要快得多。

“ Suckerfish”菜单 ( A "Suckerfish" Menu )

A "suckerfish" menu can operate entirely without JavaScript (except in IE6). The menus will open when the mouse hovers over them and close when the mouse is removed. Such opening and closing will be instant with the menu just appearing and disappearing. By adding some JavaScript we can have the menu appear to scroll out when the mouse moves over it and scroll back in when the mouse moves off of it giving a nicer appearance to the menu without affecting the way the menu works.

“ suckerfish”菜单完全可以在没有JavaScript的情况下运行(IE6中除外)。 当鼠标悬停在菜单上时,菜单将打开;而当鼠标移开时,菜单将关闭。 这样的打开和关闭将在菜单出现和消失时立即实现。 通过添加一些JavaScript,我们可以使菜单显示在鼠标移到菜单上时滚动出来,并在鼠标移开它时向后滚动,从而使菜单看起来更美观,而不影响菜单的工作方式。

JavaScript增强了您的网页 ( JavaScript Enhances Your Web page )

In all appropriate uses of JavaScript, the purpose of the JavaScript is to enhance the way the web page works and to provide those of your visitors who have JavaScript enabled with a friendlier site than is possible without the JavaScript. By using JavaScript in an appropriate way you encourage those who have a choice as to whether they will allow the JavaScript to run or not to actually have it turned on for your site. Remember that a number of those who do have a choice and who have chosen to turn JavaScript off have done so due to the way in which some sites completely misuse javaScript so as to make their visitor's experience of their site worse rather than better. Don't you be one of those using JavaScript inappropriately and therefore encouraging people to turn off JavaScript.

在JavaScript的所有适当用法中,JavaScript的目的是增强网页的工作方式,并为启用了JavaScript的访问者提供比没有JavaScript时更友好的网站。 通过以适当的方式使用JavaScript,您可以鼓励那些可以选择是否允许运行JavaScript的人为您的网站实际启用它。 请记住,由于某些站点完全滥用JavaScript的方式使访问者对其站点的体验变差了,而不是变得更好,因此许多确实有选择并且选择关闭JavaScript的人都这样做了。 您是不是不恰当地使用JavaScript并因此鼓励人们关闭JavaScript的人之一。

翻译自: https://www.thoughtco.com/why-javascript-2037560

javascript使用

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值