onclick双段元素编号

时间:2016-12-10 11:26:48

标签: javascript html events dom javascript-events

伙计所以我有12个段落,我需要做的是当我点击它时,文本必须加倍(元素加倍),基本上行数必须加倍,事情是当段落有1000个元素,它不能加倍。好的,我在这里有我的HTML代码:

<div id="pastraipos">
<p>is simply dummy text of the printing and typesetting industry. </p>
<p>it is a long established fact that a reader will be distracted.</p>
<p>There are many variations of passages of Lorem Ipsum available.</p>
<p>is simply dummy text of the printing and typesetting industry. </p>
<p>is simply dummy text of the printing and typesetting industry. </p>
<p>is simply dummy text of the printing and typesetting industry. </p>
<p>is simply dummy text of the printing and typesetting industry. </p>
<p>is simply dummy text of the printing and typesetting industry. </p>
<p>is simply dummy text of the printing and typesetting industry. </p>
<p>is simply dummy text of the printing and typesetting industry. </p>
<p>is simply dummy text of the printing and typesetting industry. </p>
<p>is simply dummy text of the printing and typesetting industry. </p>
</div>

所以我理解我需要事件,并循环该事件监听器,所以我可以对所有段落产生相同的效果。

var lala = document.getElementById('pastraipos');
var lala1 = lala.childElementCount;

function F2(){
    for (i = 0; i < lala1; i++){
    var cln = lala.children[i].cloneNode(true);
    lala.appendChild(cln)[i+1];
  }
}

for (var k = 0; k < lala1; k++) {
            lala.children[k].addEventListener('click', F2, false);
} 

它使所有段落加倍的问题,并且无法弄清楚段落中有1000个元素(空间计数),感谢您的帮助!

0 个答案:

没有答案