解析谷歌同样但不同结果的代码

开发 前端
看不出问题的时候要仔细看开发工具的每行,不只是出问题的那行,之前调试程序错误的时候就经常是因为;或者是"<"去了没">"回来。

先看一段代码

  1. > 
  2. <html> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  5. <title>课后作业管理系统title> 
  6. <style> 
  7. @charset "utf-8";  
  8. * {  
  9.     margin:0px;  
  10.     padding:0px;  
  11. }  
  12. .ipt {  
  13. width: 228px;  
  14. height: 38px;  
  15. line-height: 38px;  
  16. border: 1px solid #84A4C1;  
  17. padding: 0 9px;  
  18. margin-right: 10px;  
  19. }  
  20.  
  21.  
  22. style> 
  23. head> 
  24. <body> 
  25.         <form class="index_form"> 
  26.         <input type="text" class="ipt"/> 
  27.         <input type="password" class="ipt"/> 
  28.          form> 
  29. body> 
  30. html> 

再看一段代码

  1. > 
  2. <html> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  5. <title>课后作业管理系统title> 
  6. <style> 
  7. @charset "utf-8";  
  8. * {  
  9.     margin:0px;  
  10.     padding:0px;  
  11. }  
  12. .ipt {  
  13. width: 228px;  
  14. height: 38px;  
  15. line-height: 38px;  
  16. border: 1px solid #84A4C1;  
  17. padding: 0 9px;  
  18. margin-right: 10px;  
  19. }  
  20.  
  21.  
  22. style> 
  23. head> 
  24. <body> 
  25.         <form class="index_form"> 
  26.         <input type="text" class="ipt"/> 
  27.         <input type="password" class="ipt"/> 
  28.          form> 
  29. body> 
  30. html> 

他们初一看是一样的代码,执行在ie上面效果也相同,但是到了chrome浏览器上面结果却不同了,
效果如下:

***段代码结果

第二段代码结果

仔细看盒子模型里面的内容是不是不同,一个是228,一个是208,但是我们前面代码里面分明都是用的width: 228px;height: 38px;为什么第二段代码不是呢,然后我仔细看了下开发人员工具styles的具体内容,比较了两则执行的不同,

发现不正常的那个多了一段话:

user agent stylesheet

 

input:not([type="image"]), textarea {
box-sizing: border-box;
}

然后我比较了两段代码,在记事本里面,在editPlus里面不好看,在记事本以下就看清了,原来是***行里面分别是

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">和

DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

不知道大家看出来了么?

里面引号的状态不同,一个是英文下面的,一个是中文下面的,看来中英文害死人啊,

现在再回到开发人员工具

其实***行就有问题了

只是先前一直觉得有问题但是没仔细去看,

正确的是:

错误的是

也就是中文那个没正常执行。

综上:有时候不能正常显示,但看不出问题的时候要仔细看开发工具的每行,不只是出问题的那行,之前调试程序错误的时候就经常是因为;或者是"<"去了没">"回来。细节害死人啊,编程要养成良好的习惯,否则容易犯书写上的问题。

原文地址:http://www.cnblogs.com/sh7ning/archive/2012/04/09/2438393.html

责任编辑:张伟 来源: sh7ning的博客
相关推荐

2021-11-16 07:52:24

前端技术编程

2017-09-15 09:59:40

大数据PaddlePaddlTensorFlow

2019-10-14 10:09:28

ApacheHiveSpark

2013-11-08 14:43:37

服务商轻应用

2013-04-28 09:48:20

google glas

2009-11-05 09:01:41

WinForm

2011-08-08 10:38:38

存储虚拟化

2011-08-08 09:50:06

存储虚拟化

2009-10-16 17:49:05

综合布线产品

2011-08-18 09:40:51

SQL Server根据语言查询

2020-04-15 16:10:30

谷歌AI冠状病毒

2015-08-11 09:51:06

谷歌重组Alphabet

2019-03-12 17:17:44

华为云

2023-07-31 14:14:23

2012-11-16 10:14:54

Windows 8

2022-07-21 10:54:44

网络安全诈骗

2019-05-06 07:53:13

AnthosAzure Stack容器

2021-09-22 15:09:37

SSL证书数据安全数据泄露

2011-07-20 09:27:10

项目团队

2010-08-03 17:23:41

NFS服务
点赞
收藏

51CTO技术栈公众号