- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>自动加入隐藏文字</title>
- <style>
- .test {color:#fff;margin-left:18px;}
- </style>
- </head>
- <body>
- <p>在文章各个段落的最后加入带连接的隐藏文字</p>
- <p>在文章各个段落的最后加入带连接的隐藏文字</p>
- <script>
- function test()
- {
- var myP = document.getElementsByTagName("p");
- for(var i=0;i<myP.length;i )
- {
- var createLink = document.createElement("a");
- createLink.setAttribute("class","test");
- createLink.setAttribute("href","http://www.baidu.com/");
- createLink.setAttribute("target","new");
- var createText = document.createTextNode("百度一下");
- createLink.appendChild(createText);
- myP[i].appendChild(createLink);
- }
- }
- window.onload = function() {test();}
- </script>
- </body>
- </html>
这里忘了一个很重要的内容需要说明:并不是所有的overflow属性效果都一样,比如visible属性就只能对IE起作用。这样的话就有一个问题啦,如果要有高度,而且内容超出高度的时候,定义auto或hidden都可能会有一些不想要的效果出现。在这里提供一个解决方案:对于IE6及以下版本的IE,可以直接定义高度;对于IE8、火狐、Opera、Chrome可定义min-height。方法如下:
- overflow{
- height:auto;
- _height:200px;
- min-height:200px;
- verflow:auto;
- zoom:1;
- _overflow:visible;
- }