如何正确使用span元素 [英] How do I correctly use the span element

查看:101
本文介绍了如何正确使用span元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须接受这句话

I have to take the phrase

"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."





将文本分成一个单词数组。

在每一步迭代该数组:

随你构建SPAN元素,以及示例中显示的属性

将SPAN元素添加到原始DIV

向SPAN元素添加单击处理程序,或者到DIV,这会导致SPAN上的样式在鼠标悬停时发生变化。



我不一定要求某人为我做这件事,我只需要一个点关于我应该从哪里开始的正确方向


and
Divide the text into an array of words.
Iterate over that array, at each step:
Build SPAN elements as you go, along with the attributes as shown in the example
Add the SPAN elements to the original DIV
Add a click handler to the SPAN elements, or to the DIV, which causes the style on the SPAN to change on mouseover.

Im not necessarily asking someone to do it for me, I just need a point in the right direction as to where I should start

推荐答案

  1. 将文本划分为ar光线。



    使用 JavaScript String split()方法 [ ^ ]

  2. 在每一步迭代该数组:



    使用For循环。

  1. Divide the text into an array of words.


    Use JavaScript String split() Method[^]
  2. Iterate over that array, at each step:


    Use For Loop.
for (var i=0; i < myArray.length; i++)
{
    // Do something.
}





  • 随时构建SPAN元素,以及示例中显示的属性。





    • Build SPAN elements as you go, along with the attributes as shown in the example.


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



    • 将SPAN元素添加到原始DIV




    • Add the SPAN elements to the original DIV


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



    • 向SPAN元素或DIV添加点击处理程序,这会导致SPAN上的样式在鼠标悬停时更改。




    • Add a click handler to the SPAN elements, or to the DIV, which causes the style on the SPAN to change on mouseover.


      yourSpan.onmouseover = function () {
          alert("On MouseOver");
      
          // Do anything you want.
      }




    • 我建​​议你先从文本中划分变成一个单词的数组。 String.split 函数可以帮助你:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split [ ^ ]
      I'd suggest you start by dividing the text into an array of words. The String.split function should help you out there: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split[^]


      这篇关于如何正确使用span元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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