说我有很多div,每个div在点击时触发一个事件 [英] say I have many divs and each div trigger an event when clicked

查看:571
本文介绍了说我有很多div,每个div在点击时触发一个事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dojo 1.7
说我有很多div,每个div在点击时触发一个事件。所以当我捡起一个div时,dojo添加了一个类,就是说clicked到div。但是如何设置它,所以当我点击另一个div,它删除之前的div类点击,并将它给我刚刚点击的div?
这是因为如果我点击一个div,它应该改变它的背景,并从以前点击的div
中删除背景谢谢!!!

解决方案

您可以将所有这些div放在一个容器中,例如

 < div类= 'RadioDivContainer' > 

< div> < / DIV>
....
< div> < / DIV>

< div>

然后在divs的onclick事件处理程序中执行此操作:


$ b $ ($($)$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b});

dojo.addClass(evt.target,clicked);

这只是显示如何实现它的想法。您可以根据自己的情况进行更改。


Dojo 1.7 say I have many divs and each div trigger an event when clicked. So when I cilck a div, dojo adds a class, say "clicked" to the div. But how can I set it so when I click another div, it removes the previous div class "clicked" and gives it to the div that I just clicked? This is because if I clicked on one div it supposed to change its background and remove the background from the previously clicked div Thanks!!!

解决方案

You can put all these div in one container, for example

<div class='RadioDivContainer'>

  <div> </div>
  ....
  <div>  </div>

<div>

Then do this in onclick event handler of divs:

dojo.query(".RadioDivContainer .clicked").forEach(function(node){
     dojo.removeClass(node, "clicked");
}); 

dojo.addClass(evt.target, "clicked");

This is just show the idea how to implement it. You can change it to suit your case.

这篇关于说我有很多div,每个div在点击时触发一个事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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