CSS和JavaScript控制段落最后自动添加指定的隐藏文字,不建议这样用,由于对搜索引擎不太友好。不过做为一项技巧来研究,下面帖出具体的代码,以供参考指正:html
01 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
02 |
< html xmlns = "http://www.w3.org/1999/xhtml" > |
03 |
< head > |
04 |
< meta http-equiv = "Content-Type" content = "text/html; charset=gb2312" /> |
05 |
< title >自动加入隐藏文字</ title > |
06 |
< style > |
07 |
.test {color:#fff;margin-left:18px;} |
08 |
</ style > |
09 |
</ head > |
10 |
< body > |
11 |
< p >在文章各个段落的最后加入带链接的隐藏文字</ p > |
12 |
< p >在文章各个段落的最后加入带链接的隐藏文字</ p > |
13 |
< script > |
14 |
function test() |
15 |
{ |
16 |
var myP = document.getElementsByTagName("p"); |
17 |
for(var i=0;i< myP.length ;i ) |
18 |
{ |
19 |
var createLink = document .createElement("a"); |
20 |
createLink.setAttribute("class","test"); |
21 |
createLink.setAttribute("href","http://www.baidu.com/"); |
22 |
createLink.setAttribute("target","new"); |
23 |
var createText = document .createTextNode("百度一下"); |
24 |
createLink.appendChild(createText); |
25 |
myP[i].appendChild(createLink); |
26 |
} |
27 |
} |
28 |
window.onload = function () {test();} |
29 |
</script> |
30 |
</ body > |
31 |
</ html > |
这里忘了一个很重要的内容须要说明:并非全部的overflow属性效果都同样,好比visible属性就只能对IE起做用。这样的话就有一个问题啦,若是要有高度,并且内容超出高度的时候,定义auto或hidden均可能会有一些不想要的效果出现。在这里提供一个解决方案:对于IE6及如下版本的IE,能够直接定义高度;对于IE八、火狐、Opera、Chrome可定义min-height。方法以下:app
1 |
overflow{ |
2 |
height : auto ; |
3 |
_height : 200px ; |
4 |
min-height : 200px ; |
5 |
verflow: auto ; |
6 |
zoom: 1 ; |
7 |
_overflow : visible ; |
8 |
} |