基于元素样式的 RJS 条件 - Ruby on Rails
我在 Rails 应用程序中有一些 RJS。我希望能够在对 html 元素执行操作之前检查该元素的样式。
我尝试过以下方法
页面<< “if ($('current_thread_partial').style.display != 'none'){”
puts "HAPPY"
page << "}else{"
puts "SAD"
page << "}"
但条件不执行。在此示例中,无论是否显示,HAPPY 和 SAD 都会打印到控制台。有什么建议或其他方法吗?
干杯,
槽型
I have some RJS in a rails app. I'd like to be able to check the style of an html element before executing an action on that element.
I have tried the following
page << "if ($('current_thread_partial').style.display != 'none'){"
puts "HAPPY"
page << "}else{"
puts "SAD"
page << "}"
But the conditional does not execute. In the example here both HAPPY and SAD are printed to console regardless of the whether display is none or not. Any suggestions or another approach?
Cheers,
Slotishtype
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要使此代码正常工作,只需执行以下操作:
此代码将所有 JavaScript 写入页面变量,以便浏览器执行它。
您的
put
位于page << ""
语句在服务器端执行,简单的内容尚未发送给用户。To make this code working just do:
This code writes all JavaScript into page variable so it'd be executed by browser.
Your
puts
betweenpage << ""
sentences executes on server side and simple had not been sent to user.