Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么我的jquery.hide()不起作用?_Javascript_Jquery_Ruby On Rails 3 - Fatal编程技术网

Javascript 为什么我的jquery.hide()不起作用?

Javascript 为什么我的jquery.hide()不起作用?,javascript,jquery,ruby-on-rails-3,Javascript,Jquery,Ruby On Rails 3,我有一个简单的jquery.hide()函数,它位于类为“groups”的所有div上。 但由于某种原因,它不起作用,我不知道为什么。我使用的是rails 3,并将jquery放在application.js文件中,实际的文件“edit”放在script标记中。两者都不起作用。有人知道为什么吗 这是我的.html.erb文件 <h1 class="head">Edit information</h1> <%= form_for(@user) do |f| %>

我有一个简单的
jquery.hide()
函数,它位于类为“groups”的所有div上。 但由于某种原因,它不起作用,我不知道为什么。我使用的是rails 3,并将jquery放在application.js文件中,实际的文件“edit”放在script标记中。两者都不起作用。有人知道为什么吗

这是我的.html.erb文件

<h1 class="head">Edit information</h1>
<%= form_for(@user) do |f| %>
  <%= render 'shared/error_messages', :object => f.object %>
  <div class="field">
    <%= f.label :username %><br />
    <%= f.text_field :username, :disabled => 'disabled' %>
  </div>
  <div class="field">
      <%= f.label :full_name %><br />
      <%= f.text_field :full_name%>
  </div>
  <div class="field">
    <%= f.label :email %><br />
    <%= f.text_field :email %>
  </div>
  <%= javascript_include_tag 'application' %>

  <div class="groups">
        <%= f.label :password %><br />
        <%= f.text_field :current_password %>

        <%= f.label :password_confirmation %><br />
        <%= f.text_field :current_password %>

        <%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
        <%= f.password_field :current_password %>
  </div>

  <% if current_user.has_role? :Admin %>
  <div class="field">
  <div style="width:150px"><legend >Group</legend>
      <table border="1" width="100%">
      <tr>
            <th></th>
            <th></th>
      </tr>
      <% for role in @roles %>
      <tr>
            <td><%= role.name %></td>
            <td><%= check_box_tag "user[role_ids][]", role.id, @user.roles.include?(role) %></td>
      <tr>
      <% end %>
      </table>
      </div>
  </div>
<% else %>
<% end %>
<div class="actions">
    <%= f.submit "Update" %>
</div>
<% end %>
<%= button_to 'Back', user_path(@user) %>
function (){
    $('.groups').hide();
};
值得注意的是,我尝试过:

$(document).ready (function (){
    $('.groups').hide();
});
还有

application.js文件会像jquery一样加载到页面中。 这是漫长的一天的代码,所以我可能错过了一些明显的东西

更新

<!DOCTYPE html>
<html>
  <head>
    <title>PadOnRails | Edit user</title>
      <meta name="csrf-param" content="authenticity_token"/>
<meta name="csrf-token" content="p64cHvc9nuBXOOHeV08Kg9FBsRxgQZlehw2xetHs57c="/>
      <!-- Stylesheets -->
<link href="/stylesheets/custom.css?1313743921" media="screen" rel="stylesheet" type="text/css" />
<link href="/stylesheets/blueprint/screen.css?1313067331" media="screen" rel="stylesheet" type="text/css" />
<link href="/stylesheets/blueprint/print.css?1312273016" media="print" rel="stylesheet" type="text/css" />
<link href="/stylesheets/jquery-ui.css?1313072205" media="screen" rel="stylesheet" type="text/css" />
      <script src="/javascripts/jquery-1.6.2.min.js?1312273015" type="text/javascript"></script>

<script src="/javascripts/jquery-ui-1.8.14.custom.min.js?1312273015" type="text/javascript"></script>
<script src="/javascripts/jquery_ujs.js?1312273015" type="text/javascript"></script>
<script src="/javascripts/jquery.dataTables.min.js?1312800139" type="text/javascript"></script>
<script src="/javascripts/datatable.js?1313666950" type="text/javascript"></script>
<script src="/javascripts/rails.validations.js?1312877646" type="text/javascript"></script>  
<script src="/javascripts/error_messages.js?1313056625" type="text/javascript"></script>
<script src="/javascripts/jquery.dataTables.columnFilter.js?1312807797" type="text/javascript"></script>
<script src="/javascripts/application.js?1313762558" type="text/javascript"></script>

    </head>

    <body>
        <!-- Container for all the content on the page -->
        <div class="container header">
            <header>
    <div id="top-menu">
        <div id="account">
        <ul>
        <li>Logged in as: <b>admin</b>&nbsp;&nbsp;</li>

        <li>Current IP: <b>127.0.0.1</b>&nbsp;&nbsp;</li>
        <li><a href="/users/6" class="round">My Account</a></li>
        <li><a href="/logout" class="round">Sign out</a></li>
        </ul>
        </div>
        <ul>
        <li><a href="/" class="round">Home</a></li>

        </ul>
    </div>
</header>

            <div class=" maintitle">
                <div class="lefthead">
                 <a href="/"><img alt="Matflo" src="/images/logo.png?1312273015" /></a>
                </div>
                <div class="righthead">
                PAD
                </div>

            </div>
        </div>
                  <!-- Get contents from pages -->
                <div class="container main">
                <!-- Messages Blueprint => :error [red], :success [green], :info [blue] and :notice [yellow] -->
                <h1 class="head">Edit information</h1>
<form accept-charset="UTF-8" action="/users/6" class="edit_user" id="edit_user_6" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="p64cHvc9nuBXOOHeV08Kg9FBsRxgQZlehw2xetHs57c=" /></div>



  <div class="field">
    <label for="user_username">Username</label><br />

    <input disabled="disabled" id="user_username" name="user[username]" size="30" type="text" value="admin" />
  </div>
  <div class="field">
      <label for="user_full_name">Full name</label><br />
      <input id="user_full_name" name="user[full_name]" size="30" type="text" value="admin" />
  </div>
  <div class="field">
    <label for="user_email">Email</label><br />

    <input id="user_email" name="user[email]" size="30" type="text" value="admin@dai.co.uk" />
  </div>

  <div class="groups">
        <label for="user_password">Password</label><br />
        <input id="user_current_password" name="user[current_password]" size="30" type="text" />

        <label for="user_password_confirmation">Password confirmation</label><br />
        <input id="user_current_password" name="user[current_password]" size="30" type="text" />

        <label for="user_current_password">Current password</label> <i>(we need your current password to confirm your changes)</i><br />

        <input id="user_current_password" name="user[current_password]" size="30" type="password" />
  </div>

  <div class="field">
  <div style="width:150px"><legend >Group</legend>
      <table border="1" width="100%">
      <tr>
            <th></th>
            <th></th>

      </tr>
      <tr>
            <td>Developer</td>
            <td><input id="user_role_ids_" name="user[role_ids][]" type="checkbox" value="1" /></td>
      <tr>
      <tr>
            <td>Corporate</td>
            <td><input id="user_role_ids_" name="user[role_ids][]" type="checkbox" value="2" /></td>

      <tr>
      <tr>
            <td>ProjectManager</td>
            <td><input id="user_role_ids_" name="user[role_ids][]" type="checkbox" value="3" /></td>
      <tr>
      <tr>
            <td>Admin</td>
            <td><input checked="checked" id="user_role_ids_" name="user[role_ids][]" type="checkbox" value="4" /></td>

      <tr>
      <tr>
            <td>TeamLeader</td>
            <td><input id="user_role_ids_" name="user[role_ids][]" type="checkbox" value="5" /></td>
      <tr>
      <tr>
            <td>Engineer</td>
            <td><input id="user_role_ids_" name="user[role_ids][]" type="checkbox" value="6" /></td>

      <tr>
      </table>
      </div>
  </div>
<div class="actions">
    <input id="user_submit" name="commit" type="submit" value="Update" />
</div>
</form><form method="post" action="/users/6"  class="button_to"><div><input type="submit" value="Back" /><input name="authenticity_token" type="hidden" value="p64cHvc9nuBXOOHeV08Kg9FBsRxgQZlehw2xetHs57c=" /></div></form>

            </div>
        </div>

        <!-- Debug information outside page container- REMOVE WHEN FINISHED! -->
    </body>
    <div class="container">
    <div id="bottom-menu">
        <pre class='debug_dump'>--- !map:ActiveSupport::HashWithIndifferentAccess 
action: edit
id: &quot;6&quot;
controller: users
</pre>
    </div>
    </div>

</html>

PadOnRails |编辑用户
  • 以管理员身份登录
  • 当前IP:127.0.0.1
衬垫 编辑信息 用户名
全名
电子邮件
密码
密码确认
当前密码(我们需要您的当前密码来确认您的更改)
组 开发商 公司的 项目经理 管理 队长 工程师 --- !映射:ActiveSupport::HashWithInferenceTaccess 操作:编辑 id:“6” 控制器:用户

Html根据要求直接从源代码中获取。

确保未包含原型,任何库都可以使用“$”。试试这个:

jQuery(document).ready(function(){
    jQuery(".groups").hide();
});

额外:如果您使用HTML元素编写脚本,正确的方法是使用双引号(“”)。

您是否在application.js include之前包含jquery.js文件?它是否将带有类组的div的设置更改为任何…?在这里看不到任何错误,尝试发布生成的HTML。我无法重现该问题。我真的不知道为什么它不起作用。我甚至重新启动了我的服务器。更好:
jQuery(document).ready(函数($){$(“.groups”).hide();})不,两者都不起作用…这真的很奇怪,但似乎合乎逻辑