首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >循环Javascript中的Span

循环Javascript中的Span
EN

Stack Overflow用户
提问于 2014-05-01 11:46:42
回答 2查看 1.1K关注 0票数 0

我有代码

代码语言:javascript
复制
function splitString(stringToSplit, separator) {

var str= "It’s that time of year when you clean out your closets, dust off shelves, and spruce up your floors. Once you’ve taken care of the dust and dirt, what about some digital cleaning? Going through all your files and computers may seem like a daunting task, but we found ways to make the process fairly painless."
var myArray = stringToSplit.split(" ")



for (var i=0; i < myArray.length; i++)
{

}
var yourSpan = document.createElement('span');
yourSpan.innerHTML = "";

var yourDiv = document.getElementById('divId');
yourDiv.appendChild(yourSpan);

yourSpan.onmouseover = function () {
    alert("On MouseOver");

}

对于html,我有

代码语言:javascript
复制
<div id="transcriptText"> It’s that time of year when you clean out your
closets, dust off shelves, and spruce up your floors. Once you’ve taken
care of the dust and dirt, what about some digital cleaning? Going
through all your files and computers may seem like a daunting task, but
we found ways to make the process fairly painless.</div>
<br>
<div id="divideTranscript" class="button">&nbsp;Transform the
Transcript!&nbsp; </div>T

我需要在循环中创建跨度,我需要创建一个跨度,将class和id属性(对于每个单词都不同-它包括数组的索引(i))添加到span元素,在跨度内添加单词,向跨度添加mouseover/mouseout事件侦听器,将跨度添加到原始div。有人能帮我吗?这不是很多,我只是不确定我应该如何做这些最后的改变。

EN

Stack Overflow用户

发布于 2020-12-23 07:36:25

代码语言:javascript
复制
for (let i = 0; i < raceTraits.ability.length;i++){
        document.getElementById("Race").innerHTML +=  "<span id =" + i + ">" + "</span>";
}

/*you could use the value in the for loop and plugin "i" to make this easier*/
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23401712

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档