动态添加数据以跨度标记 [英] adding data to span tag dynamically

查看:84
本文介绍了动态添加数据以跨度标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个span标签,里面有一些html代码来创建一些角落和其他东西。现在使用javascript我想给它添加一些标题。约束是span的原始内容不应该被覆盖。

I have a span tag inside with there is some html code to create some corners and other things. Now using javascript i want to add some captions to it.The constraint is the original content of span should not get overwritten.

例如

<span>  <!-some more complicated html code </span>

现在我想在span中添加标题,以便span应该看起来像

Now i want to add caption in span so that span should look like

<span> NEW CAPTION <!-some more complicated html code </span>

我该如何做?

How can i do it?

document.getElementById.innerHtml = "NEWCAPTION" + document.getElementById.innerHtml 

这是正确的吗?

推荐答案

如果你打算这么做,你需要给span一个ID。 innerHtml也应该是 innerHTML

You will need to give the span an ID if you going to do it that way. Also the innerHtml should be innerHTML

例如。

eg.

<span id="mySpan">  <!-come more complecated html code </span>

document.getElementById('mySpan').innerHTML = "NEWCAPTION" + document.getElementById('mySpan').innerHTML

这篇关于动态添加数据以跨度标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆