当前位置: 首页 > 图文教程 > 网页制作 > CSS样式表 > CSS实现在文章每段后面加入带连接的隐藏文字

CSS样式表
shtml精简教程让你知道什么是shtml
很不错的 CSS Hack 又学了一招
Default style sheet for HTML 4
资料:Unicode 汉字内码对应表
解决CSS中 display 与 visibility 的区别
制作WEB在线编辑器-插入HTML标签
编写纯 CSS 弹出菜单的原理及实现 By shawl.qiu
关于《精通css》之几个不错的注意事项
position:relative/absolute无法冲破的等级
CSS样式表常用小技巧收藏
收集的web页面html中常用的特殊符号大全
bc1998录制的css视频教程推荐新手看下
dl+ol应用分析
li的简单应用
web打印的另类方法
用CSS实现的一张图完成的按钮效果
文章内容页广告浮于左上角的解决办法
广告放在文章页左上角的解决办法二
iframe的使用用法
FIF互动帮助手册系列-HTML手册 flash版

CSS样式表 中的 CSS实现在文章每段后面加入带连接的隐藏文字


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-11   浏览: 184 ::
收藏到网摘: n/a


代码主要理解3个参数:createElement、createTextNode、appendChild。这3个js参数分别是创建元素、创建字符、追加节点。代码原理:循环页面段落标签<p>,创建连接元素<a>,创建要显示的连接字符,用SetAttribute定义元素a的样式和连接地址。在循环标签<p>后追加创建的元素<a>。
                                      
<!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>
<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.ruanchen.com/quot;);
createLink.setAttribute("target","new");
var createText = document.createTextNode("软晨学习网");
createLink.appendChild(createText);
myP[i].appendChild(createLink);
}
}
window.onload = function() {test();}
</script>
</body>
</html>