添加Click事件在JavaScript中数组元素 [英] Adding Click event for Array Elements in javascript

查看:85
本文介绍了添加Click事件在JavaScript中数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的JavaScript
我有礼中有一个多维数组。我想添加click事件侦听所有李时珍在我的多维数组
我的数组是这样的。

  newItems = [
  [li.pL14,李,li.pR15]
  [li.pL14,李,li.pR15]
  [li.pL14,李,li.pL14]
  [李,li.pR15,li.description]
  [li.pL14,李,li.pR15]
  [li.pL14,LI]
]


解决方案

试试这个...让你newItems是元素礼的多维变量

 为(VAR I = 0; I< newItems.length;我++)
{
  对于(VAR J = 0; J< newItems [I]。长度; J ++)
  {
    newItems [I] [j]的阅读进度('点击',功能(){
      //你在点击code    },假);
  }
}

I am new to javascript I have a multi dimensional array which has 'li' in it. i want to add click event listener for all the li in my multidimensional array my array is like this

newItems = [ 
  [li.pL14, li, li.pR15], 
  [li.pL14, li, li.pR15], 
  [li.pL14, li, li.pL14], 
  [li, li.pR15, li.description], 
  [li.pL14, li, li.pR15], 
  [li.pL14, li]
]

解决方案

Try this ...Let your newItems is the MultiDimensional variable of element "li"

for(var i=0;i<newItems.length;i++)
{
  for(var j=0;j<newItems[i].length;j++)
  {
    newItems[i][j].addEventListener('click',function(){
      // Your On Click code

    },false);
  }
}

这篇关于添加Click事件在JavaScript中数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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