2013-02-24 76 views
-1

很简单,“.hide()”功能不起作用。我正在使用jquery-rails gem,并且在application.js中有适当的语句。jquery隐藏功能不起作用

这里是我的代码:

<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" /> 
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> 
<link rel="stylesheet" href="/resources/demos/style.css" /> 

<script> 
$(document).ready(function() { 
    $(document).ajaxSuccess(function() { 
     $("#ld").hide(); 
     //alert('Hooray!'); 
    }); 
}); 
</script> 

在布局/ application.html.erb我

<!DOCTYPE html> 
<html> 
    <head> 
     <title><%= full_title(yield(:title)) %></title> 

     <%# two lines below allow for device-responsive formatting, see twitter-bootstrap page%> 
     <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
     <link href="assets/css/bootstrap-responsive.css" rel="stylesheet"> 

     <%= stylesheet_link_tag "application", media: "all" %> 
     <%= javascript_include_tag "application" %> 
     <%= javascript_include_tag :highcharts %> 
     <%= csrf_meta_tags %> 
     <%= render 'layouts/shim' %> 
    </head> 

    <body> 
     <%= render 'layouts/header' %> 
     <div class="container"> 
     <%= yield %> 
     <%= render 'layouts/footer' %> 
     <%= debug(params) if Rails.env.development? %> 
     </div> 
    </body> 
</html> 

编辑:

1)如果我改改这个, hide()仍然不起作用。在浏览器中查看页面源代码时,我也清楚地看到了assets/jquery.js。

<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" /> 
<script src="http://code.jquery.com/jquery-1.8.3.js"></script> 
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> 
<link rel="stylesheet" href="/resources/demos/style.css" /> 

2)在HTML我有:

<div id="#ld"> 
    <%= image_tag("ajax-loader.gif", :alt => "test image") %> 
</div> 
+0

.css()不起作用...我在哪里可以在查看页面源时找到这些定义? – Krishna 2013-02-24 00:04:42

+4

你可以请把包括由此产生的HTML而不是一些红宝石模板。我无法找到你的标签ID为“ld”的应该是... – 2013-02-24 00:06:29

+2

你有jQuery吗?您的HTML仅显示jQuery UI脚本。 – 2013-02-24 00:06:40

回答

1

从您的div的ID删除#哈希:

<div id="ld"> 

你只投入CSS和jQuery嘶嘶选择到哈希说你正在寻找一个id,而不是一个类(.)或标签名称(没有前缀)。