Writing high-quality code-basics: structure and style, separation of behavior, and high quality --

Source: Internet
Author: User

Writing high-quality code-basics: structure and style, separation of behavior, and high quality --
To implement high-quality code, we need to separate the structure, style, and behavior to simplify, reuse, and order. Streamline: Minimize the file size and increase the page loading speed. Reuse: Improves code reusability, reduces redundant code, and increases development speed. ORDERLY: Improve the code structure and organize the code structure to facilitate maintenance and adapt to special situations. In our work, you may encounter such code, or you may write such code.

<Td width = "100%" height = "20" class = "f9pt" align = "center"> <font color = "# 0000f0e"> download </font> <input type = "text" name = "wd" size = "40" onMouseOver = "this. focus () "onFocus =" this. select () "style =" margin-bottom:-5px; font-size: 16px; height: 1.78em; font-family: arial, sans-serif, padpadpad; ding-top: 2px; padding-left: 1px "maxlength =" 100 "> </td>
What a beautiful code .... First of all, let's not talk about the rationality of the code. We only discuss the code standards. The code here does not follow the most basic web standard-the separation of structure style and behavior. The above code is a piece of html, css, and js Code. To improve web page performance and facilitate team development, we should separate the structure, style, and behavior with separate files, as shown below. Test.html file:
<Link rel = "stylesheet" type = "text/css" href1_1_test.css "/> <td class =" f9pt myTd "> <span class =" myFont "> download </span> <input type = "text" name = "wd" size = "40" id = "myInput" maxlength = "100"/> </td> <script type = "text/ javascript "src =" test. js "> </script>
Test.css file:
. MyTd {width: 100%; height: 20px; text-align: center ;}. myFont {color: # 0000f0e ;}# myInput {margin-bottom:-5px; font-size: 16px; height: 1.78em; font-family: arial, sansserif,; padding-top: 2px; padding-left: 1px}
Test. js File
var myInput = document.getElementById(“myInput”);  myInput.onmouseover = function(){  this.focus();}myInput.onfocus = function(){  this.select();}

 

Or if you must write it on an html page, you 'd better use the style and script labels as follows.
<Style type = "text/CSS">. myTd {width: 100%; height: 20px; text-align: center ;}. myFont {color: # 0000f0e ;}# myInput {margin-bottom:-5px; font-size: 16px; height: 1.78em; font-family: arial, sansserif,; padding-top: 2px; padding-left: 1px} </style>

<Td class = "f9pt myTd">
<Span class = "myFont"> download </span>
<Input type = "text" name = "wd" size = "40" id = "myInput" maxlength = "100"/>
</Td> <script type = "text/Javascript"> var myInput = document. getElementById ("myInput"); myInput. onmouseover = function () {this. focus ();} myInput. onfocus = function () {this. select () ;}</script>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.