input的value中有特殊字符

今天碰到了一个html的问题,如果input的value里有特殊字符">","\""时,浏览器显示会出现异常,代码如下

 1 <!doctype html>
 2 <html>
 3     <head>
 4         <title>测试特殊字符</title>
 5         <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
 6     </head>
 7     <body>
 8         <!-- 下面两个text域的value都是  测试"测试>测试 -->
 9         <input type="text" value="测试\"测试>测试" />
10         <br/><br/>
11         <input type="text" value="测试&quot;测试&gt;测试" />
12     </body>
13 </html>

显示效果:

解决办法就像上面第二个input一样,将特殊字符用其对应的实体名称代替,就能够正常显示了

参考:http://www.runoob.com/html/html-entities.html

posted @ 2016-03-23 00:13  追忆流年时光  阅读(994)  评论(0编辑  收藏  举报