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 |
} |