如何绕过rails上的ruby中的jquery链接? [英] How to bypass jquery link in ruby on rails?

查看:97
本文介绍了如何绕过rails上的ruby中的jquery链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







我正在研究rails项目上的ruby。在特定的视图页面中,我使用了jQuery。这个页面有一个表(例如)10列。最初只显示5列,其余部分隐藏。为了隐藏列我使用了jQuery。我已经包含了jquery-rails gem jquery-ui gem以及在application.js中完成的所有必要的更改。但如果我不添加

< script src =https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js>< / script>



隐藏不起作用。我在下面添加了代码片段。

PS在head元素中添加了javascript;使用turbolinks

如果我删除jquery链接;隐藏不起作用。



任何人都可以解决以下问题吗?谢谢



我尝试过:



< HTML> 
< head>

< script src = https://ajax.googleapis.com/ajax/库/ jquery的/ 1.12.0 / jquery.min.js>< /脚本>

< script type = text / javascript>
$( document )。ready( function (){

// 最初隐藏周cols


< ;%@ colwno.each 执行 | s | %>
$(' td:nth-​​child(<%= s%>)')。hide();
$(' #try1 th:nth-​​child(<%= s%>)')。hide();

<%end %>

< / script>

解决方案

document )。ready(功能(){

// 最初隐藏周cols


<%@ colwno.each do | s | %>


' td:nth-​​child(<%= s%>)')。hide() ;


' #try1 th:nth-​​child(<%= S(%)>)')隐藏();

<%end %>

< / script>


Hi,


I'm working on a ruby on rails project. In a particular view page, I have used jQuery. This page has a table with (say ) 10 columns. Initially only 5 columns is show and rest are hidden. For hiding columns I have used jQuery. I have included jquery-rails gem jquery-ui gem and all necessary changes to be done in application.js is done. But if I do not add
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

hiding is not working. I have added code snippet below.
PS added javascript inside head element; using turbolinks
If I remove jquery link ; hiding is not working.

Can anyone solve the below issue ? Thanks

What I have tried:

<html>
<head>

     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
     
      <script type="text/javascript">
         $(document).ready(function(){

                 // to hide the week cols initially


                  <%  @colwno.each do |s|%> 
                        $('td:nth-child(<%=s%>)').hide();
                        $('#try1 th:nth-child(<%=s%>)').hide();
                       
                   <% end %>

      </script> 

解决方案

(document).ready(function(){ // to hide the week cols initially <% @colwno.each do |s|%>


('td:nth-child(<%=s%>)').hide();


('#try1 th:nth-child(<%=s%>)').hide(); <% end %> </script>


这篇关于如何绕过rails上的ruby中的jquery链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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