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我有
<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"> Transform the
Transcript! </div>T
我需要跨距創建的循環中, 我需要創建一個跨度,添加類和id屬性(每個單詞都有所不同 - 它包括數組(i)的索引))添加到span元素中,在span中添加單詞,向span添加mouseover/mouseout事件偵聽器,將span添加到原始DIV。 任何人都可以幫助我嗎?我只是不確定我應該如何去做這些最後的改變。
這將非常感謝你 – user3591618