Home  >  Article  >  Web Front-end  >  HTML tag programming compatibility considerations

HTML tag programming compatibility considerations

伊谢尔伦
伊谢尔伦Original
2017-06-16 10:09:551286browse

页面布局灵活,改版时只需改CSS样式即可实现页面重新布局,而不用改动程序,从而降低了网站改版的成本。 

注意标签的闭合关系,尤其是在form标签中嵌套div等其他标签时。

有的时候页面上会出现多余的空白,即使重新设置了margin也无法避免,这个时候有可能是页面元素标签闭合出现了不配对的情况,如:

<div class=”outer”>
     <form name=”testForm”>
         <div class=”inner”>
              <input name=”title” type=”text” />
         </form>
     </div> 
</div>

定义table时使用tbody元素,以保证包括IE在内的所有浏览器可正确使用

即使table没有显示定义tbody元素,浏览器也会认为tr节点的父节点是一个自动添加的默认tbody节点.为了避免使用javascript操纵tr节点时可能产生的误会,  还是手动添加一个比较好,如:

<table id=”myTable”>
<tbody id=”myTableBody”>
  <tr>
       <td>
</td>
</tr>
</tbody>
</table>

注意标签及属性的大小写

有的时候,有些绑定在元素上的事件在IE浏览器下响应,在safari或其他浏览器下却不响应。这时候需要检查事件绑定方式的正确性,高级事件的绑定需要区别IE和其他浏览器写两套javascript,而简单事件模型需要注意一下绑定事件名的大小写。如:

b5405acd5d4abf6fbfd512dba6dd6b9a

这里应该用小写的onfocus,并且显示的添加标签闭合符号才是规范的写法。

12d4d0645fb89f86a4be499df5ba66c7 

注意标签的属性值设置

3f1c4e4b6b16bbbd69b2ee476dc4f83a标签的language和type属性

3f1c4e4b6b16bbbd69b2ee476dc4f83a标签的language属性是用来定义脚本语言版本的,正确的赋值应该形如3f1c4e4b6b16bbbd69b2ee476dc4f83a用来告诉浏览器(主要是IE)使用1.2版本的javascript语法来解释;而type属性才是用来定义脚本类型的,是w3c的标准属性,并且使用小写属性才是符合标准的做法。如果不是特别情况下需要告诉浏览器按照较低版本的javascrip语言进行解释的话(目前大多数浏览器支持的javascript版本是1.5),一般不需要定义language属性,但是type属性是需要定义的。所以应该把代码中的

ca59691adfd8042ff4f15bfca379851e改为3f1c4e4b6b16bbbd69b2ee476dc4f83a

3499910bf9dac5ae3c52d5ede7383485The alt and title attributes of the label

Although the values ​​of the two attributes alt and title will be displayed in the form of tool tip when the mouse is hovered under IE, they still have difference. alt is the alternative display when the picture is not displayed, and title is the prompt when the mouse is placed on it.

The checked and readonly attributes of thed5fd7aea971a85678ba271703566ebfd tag

In early versions of HTML, it was not mandatory that all attributes should be assigned values. When expressing a selected check box, 12a738289f0faa85f887515226a2d4b6 This way of writing is accepted. However, according to the XHTML standard, such a grammar is not a strict XML format. Attention should be paid to the assignment of attributes and the closure of tags to comply with the development trend of HTML standards. It is written like this:

05071527de1cf3d7b7c67dd9efce81df

37f4b80455f619732cad1645cea56d9f

5a07473c87748fb1bf73f23d45547ab8The selected ed attribute of the tag

The same reason as the previous one , the selected attribute of the 5a07473c87748fb1bf73f23d45547ab8 tag in the 221f08282418e2996498697df914ce4e option should also be assigned a value:

71deefae35a4adca640c4e4736e9509d

a1f02c36ba31691bcfe87b2722de723b align= of the tag "absmiddle" attribute

According to the XHTML standard, HTML tags should focus on the presentation of content, rather than the control of style, and the style should be left to CSS adjustment. Therefore, some old tags and attributes have been abandoned. For example, the 907fae80ddef53131f3292ee4f81644b tag and 5a8028ccc7a7e27417bff9f05adf5932 tag will cause the Chinese text of the tag content to be displayed in italics, but the 5a8028ccc7a7e27417bff9f05adf5932 tag, which is simply named after a style, is already obsolete. Standard, replaced by the 907fae80ddef53131f3292ee4f81644b tag that expresses emphasis. Similarly, the align="absmiddle" attribute of the a1f02c36ba31691bcfe87b2722de723b tag indicates that the image is vertically aligned with the adjacent text. This is also an attribute indicating style. CSS should be used instead of this attribute to control the alignment style of the image to avoid two Interaction of style controls.

d5ba1642137c3f32f4f4493ae923989cThe frameborder attribute of the tag

When using iframe, in IE, you may only need to set border="0" to not display the iframe border, but the standard control frame window The attribute of the border is frameborder. You should set frameborder="0" to hide the frame's border in browsers other than IE:

45d95e0d1788444251018a04c22a40e2

The cellpadding attribute of the f5d188ed2c074f8b944552db028f98a1 tag

This attribute is the same as the align attribute of the a1f02c36ba31691bcfe87b2722de723b tag. It is also an attribute that overrides the responsibility of HTML itself to represent content and controls the style. It specifies is the space between units. From a practical point of view, it is better not to specify cellpadding, but to use CSS to control the padding of cells.

b6c5a531a458a2e790c1fd6421739d1cThe nowrap attribute of the tag

nowrap is an attribute that indicates that the content will not wrap automatically, but like the above attributes, this is an attribute that controls the style. In HTML 4.01, the "bgcolor", "height", "width" and "nowrap" tags of the b6c5a531a458a2e790c1fd6421739d1c tag are deprecated. In XHTML 1.0 Strict DTD, "bgcolor", "height", "width" and "nowrap" of the b6c5a531a458a2e790c1fd6421739d1c tag are not supported.

The above is the detailed content of HTML tag programming compatibility considerations. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn