首页 > 开发 > CSS > 正文

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

2024-07-11 08:21:40
字体:
来源:转载
供稿:网友

代码主要理解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.VeVb.com/");
  createlink.setattribute("target","new");
  var createtext = document.createtextnode("网页设计");
  createlink.appendchild(createtext);
  myp[i].appendchild(createlink);
 }
}
window.onload = function() {test();}
</script>
</body>
</html>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表