【发布时间】:2014-04-10 19:56:18
【问题描述】:
我有一个视图,其中对于一系列对象,我有几个包含详细信息的 div。对于每个 div,我都有一个 Toggle 链接。我的问题是 toggle() 仅适用于第一种 div,即注册的第一个点击事件。代码如下:
$(".class1").click (e) ->
e.preventDefault()
#get the index value I appended to this elements ID
divIndex = $(this).attr("id").replace("link1_", "")
#select and toggle the respective message
$("#div1_" + divIndex).toggle()
return
$(".class2").click (e) ->
e.preventDefault()
#get the index value I appended to this elements ID
divIndex = $(this).attr("id").replace("link2_", "")
#select and toggle the respective message
$("#div2_" + divIndex).toggle()
return
它只适用于注册的第一个点击事件。如果我更改顺序,另一个开始工作。对于第二个,它只是跟随视图中的链接。
有什么帮助吗?谢谢!
【问题讨论】:
标签: jquery ruby-on-rails coffeescript