gpt4 book ai didi

javascript - 全选/取消全选页面中的复选框

转载 作者:可可西里 更新时间:2023-11-01 02:52:58 28 4
gpt4 key购买 nike

我看过this这似乎对我的代码没有影响。我试过了 this这似乎只影响第一个复选框,但当我再次单击它时不会取消选中该复选框....我还看到了其他一些我不确定是否完全符合 Rails 风格(或任何术语)的方法。

那么,有人能给我指出正确的方向吗?

这是我的看法:

<%= render 'admin/distributions/head' %>
<% title 'Workflow' %>


<%= form_for @search, :url => url_for(:controller => params[:controller], :action => params[:action]), :html => {id => "distribution_workflow",:method => :get} do |f| %>

<div class="opportunity-block yellow">

<div class="form-block mrl mbm">
<%= f.label :created_at_gt, "Created at >" %>
<%= f.text_field :created_at_gt, :class => "js-db-date-picker" %>
</div>

<div class="form-block mrl mbm">
<%= f.label :created_at_lte, "Created at <=" %>
<%= f.text_field :created_at_lte, :class => "js-db-date-picker" %>
</div>

<div class="form-block mrl mbm mtm">
<%= f.label :status_equal, "Status" %>
<%= f.select :status_equal, %w(delivered no_success already_registered qa_complete success follow_up), :include_blank => " " %>
</div>

<div class="clear"></div>
<%= submit_tag 'Apply Filter', :class => "input-button dark unit-right mrl" %>
<div class="clear"></div>
</div>
<% end %>


<%= form_tag edit_multiple_admin_distributions_workflows_path , :id => "workflow_form" do %>
<%= submit_tag "Edit Selected" %>
<table class="standard-grid">
<tr>
<th class="first"> </th>
<th>ID</th>
<th>Customer</th>
<th>Resume URL</th>
<th>Partner</th>
<th>Status</th>
<th>Assigned To</th>
<th>Comments</th>
</tr>
<% @report.each do |distribution| %>
<tr>
<td><%= check_box_tag "distribution_ids[]", distribution.id %></td>
<td>
<%= distribution.owner.id %>
</td>
<td>
<%=link_to distribution.owner.full_name, "mailto:#{distribution.owner.email}" %>
</td>
<td>
<a href=<% UrlService.download_blob_url(distribution.resume) %>>Resume URL</a>
</td>
<td>
<%=link_to distribution.matching_profile.partner.title, "mailto:#{distribution.matching_profile.partner.email}" %>
</td>
<td>
<%= distribution.status %>
</td>
<td>
<%= distribution.assignee_id ? User.find(distribution.assignee_id).full_name : " " %>
</td>
<td>
<%= distribution.comments %>
</td>
</tr>
<% end %>
</table>
<% end %>

最佳答案

这是一个适用于您的示例:http://jsfiddle.net/wYPWL/

HTML 示例:

<input type="checkbox" id="selectAll" value="selectAll"> Select / Deselect All<br/><br/>

<input type="checkbox" name="foo" value="bar1"> Bar 1<br/>
<input type="checkbox" name="foo" value="bar2"> Bar 2<br/>
<input type="checkbox" name="foo" value="bar3"> Bar 3<br/>
<input type="checkbox" name="foo" value="bar4"> Bar 4<br/>

Javascript:

$('#selectAll').click(function() {
if (this.checked) {
$(':checkbox').each(function() {
this.checked = true;
});
} else {
$(':checkbox').each(function() {
this.checked = false;
});
}
});

无论您的复选框的名称如何,这都将起作用。如果您真的只想定位上面代码中显示的复选框,您可以将 $(':checkbox') 替换为 $('input[id^="distribution_ids"]') 这是 jQuery 定位 ID 以 distribution_ids

开头的输入元素的方法

关于javascript - 全选/取消全选页面中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8585572/

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