javascript - 如何将 h3 和 p 添加到 anchor 标记

标签 javascript jquery html jquery-mobile

我想动态添加一个header元素和两个<p> anchor 标签内的标签。

下面是我要实现的代码。

<a href="http://shreerangpatwardhan.blogspot.com" class= "ui-list">
  <h3>Author: Shreerang Patwardhan</h3>
  <p><b>Description:</b> Spatial Unlimited is a Tech blog where, examples using Google Maps API v3 and Jquery Mobile are shared. I have tried to give back to the developer community as much as I can.</p>
  <p class="ui-li-aside">Last update: April 9, 2013</p>
</a>

下面是我正在尝试制作的 javascript

var a =document.createElement("a");
var h3=document.createElement("h3");
var p=document.createElement("p");
var p1=document.createElement("p");
a.setAttribute('href', "#");
h3.setAttribute('value',"Author:"+name);
p.setAttribute('value',"Description"+finalsummary);
p1.setAttribute('value',"Last update:"+finaldate);
p1.setAttribute("class","ui-li-aside");
a.appendChild(p1);
a.appendChild(p);
a.appendChild(h3);

但标签没有被附加。

最佳答案

输入字段有值,标签有textContent或兼容,innerHTML

var name="Shreerang Patwardhan"
var finalsummary ="Spatial Unlimited is a Tech blog where, examples using Google Maps API v3 and Jquery Mobile are shared. I have tried to give back to the developer community as much as I can.";
var finaldate = new Date().toLocaleString();
var a =document.createElement("a");
var h3=document.createElement("h3");
var p=document.createElement("p");
var p1=document.createElement("p");
var li = document.createElement("li");
a.setAttribute('href', "#");
h3.innerHTML="Author: "+name;
p.innerHTML="Description: "+finalsummary;
p1.innerHTML="Last update:"+finaldate;
p1.setAttribute("class","ui-li-aside");
a.appendChild(p1);
a.appendChild(p);
a.appendChild(h3);
li.appendChild(a)
document.getElementById("content").appendChild(li);
<ul id="content"></ul>

关于javascript - 如何将 h3 和 p 添加到 anchor 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30004250/

相关文章:

javascript - 使用 javascript 按 id 对列表进行排序

javascript - JQuery 替换的链接在 IE 8-10 下不起作用

javascript - jQuery 变量改变值并发出警报

javascript - 映射对象数组返回未定义

javascript - Grails、javascript 渲染模板后不响应

javascript:用 new 调用函数时可以创建静态变量吗?

jquery - 加载到引导模式时我的搜索输入不起作用

javascript - 在这个 jsfiddle 示例中,如何让滚动停止传播

javascript - 如何过滤表格,在json数据中找到匹配的条目并添加相应的链接

javascript - 计算一个 div 中的 div 数量,在一页 wordpress 帖子上有多个父 div