【问题标题】:How to add a h3 and p to an anchor tag如何将 h3 和 p 添加到锚标记
【发布时间】:2015-07-12 07:28:03
【问题描述】:

我想在锚标记内动态添加一个标题元素和两个<p> 标记。

下面是我要实现的代码。

<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);

但标签没有被附加。

【问题讨论】:

  • 这可能工作得很好,但你永远不会将锚附加到任何东西上`
  • P也没有价值
  • 嗨,我将这个锚标记附加到 li 元素并将 li 附加到 ui

标签: javascript jquery html jquery-mobile


【解决方案1】:

你可以使用jQUERY:

$(document).ready(function(){
$(".ui-list").append('<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>');
});

【讨论】:

    【解决方案2】:

    输入字段有值,标签有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);
    &lt;ul id="content"&gt;&lt;/ul&gt;

    【讨论】:

      猜你喜欢
      • 2020-01-15
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-29
      • 2020-07-17
      • 1970-01-01
      相关资源
      最近更新 更多