我的代码略有变化 [英] Slight changes to my code

查看:68
本文介绍了我的代码略有变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有代码

 function splitString(stringToSplit,separator){

var str = 这是一年中你清理壁橱,把架子上的灰尘和云杉弄脏的时候你的地板。一旦你处理了灰尘和污垢,一些数字清洁怎么办?浏览所有文件和计算机可能看起来是一项艰巨的任务,但我们找到了使这个过程相当轻松的方法。
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>这是一年中你清理衣柜里的灰尘,货架上的灰尘和地板上的云杉的时候。一旦你花了灰尘和污垢,那么一些数字清洁呢?通过你所有的文件和计算机来看看
可能看起来像是一项艰巨的任务,但是我们找到了使这个过程变得相当轻松的方法。< / div>

< br>

< div id =divideTranscriptclass =button>& nbsp;转换

成绩单!& nbsp ; < / div> T



我需要在循环内创建跨度,

我需要创建一个span,添加类和id属性(每个单词不同 - 它包括数组的索引(i))到span元素,在span中添加单词,将mouseover / mouseout事件监听器添加到span,将span添加到原始div .br mode =hold/>任何人都可以帮助我它不是很多我不知道该怎么做而且不想弄乱我所拥有的东西

解决方案

所以制作整个项目的副本(为此目的,我在我的Projects文件夹下保留一个名为AABackups的文件夹)并尝试进行更改。如果他们工作,罚款 - 继续。如果他们不试图修复它们。请记住,在您开始更改备份之前,您可以放弃发货并将备份复制回工作代码,这样您就可以犯下致命错误 - 您可以扔掉垃圾并重新启动。



最好的学习方法是自己尝试并(如有必要)犯错误:不要看别人做了什么! :笑:

I have the code

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

}


and for html I have
<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

I need the span creation inside the loop,
I need to create a span, add the class and id attribute (which is different for each word - it includes the index of the array (i)) to the span element, add the word inside the span, add mouseover/mouseout event listeners to the span, add the span to the original div.br mode="hold" />Can anybody help me its not much I just am not sure what to do and dont want to mess up what I have

解决方案

So make a copy of your whole project (I keep a folder under my Projects folder called "AABackups" for just this purpose) and try making the changes. If they work, fine - carry on. If they don't try to fix them. Remember at all times that you can "abandon ship" and copy your backup back to get back to working code before you started changing it, so you can;t make a "fatal" mistake - you can "throw away" rubbish and restart.

The best way to learn is to try it yourself and (if necessary) make mistakes: not to look at what someone else has done! :laugh:


这篇关于我的代码略有变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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