gpt4 book ai didi

javascript - 在coffeescript中模拟链接点击

转载 作者:行者123 更新时间:2023-11-30 14:58:04 24 4
gpt4 key购买 nike

我有一个链接,点击后会重定向到聊天页面。现在,我想从 coffeescript 代码中重定向到该页面。如何模拟下面的链接(带参数)和点击效果一样?

<%= link_to "Send", "#", class: "chat",
"data-sender" => current_user.id, "data-receiver" => user.id
%>

最佳答案

我认为您首先应该在评论部分使用与 Action 电缆相关的更新来更新问题。

像这样的事情应该可行。

received: (data) ->
sender_id = data.sender
reciever_id = data.receiver
link = $('a.chat')

link.attr('data-sender', sender_id) # To set data attributes for the link
link.attr('data-receiver', receiver_id)
link.trigger('click') # Triggering a click so that the rest of the code can take over

我不知道您的应用程序如何工作。

我想做的是更新数据属性或链接到从 Action 电缆获得的值,然后触发链接上的点击事件,以便您应用中的其余代码可以接管。

关于javascript - 在coffeescript中模拟链接点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46947176/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com