检查/取消选中位于触发我的函数的元素内的复选框的正确方法是什么?
这是我的代码:
<table id="news_list">
<tr>
<td><input type="checkbox" name="news[1]" /></td>
<td>TEXT</td>
</tr></table>
$("#news_list tr").click(function() {
var ele = $(this).find('input');
if(ele.is(':checked')){
ele.removeAttr('checked');
$(this).removeClass('admin_checked');
}else{
ele.attr('checked', 'checked');
$(this).addClass('admin_checked');
}
});
Run Code Online (Sandbox Code Playgroud)
问题是我只能检查并取消选中每个方框一次.在我检查并取消选中后,它仍然会添加/删除类,但从不再次检查一个框(即使我单击复选框,而不是表行).
我尝试过使用.bind('click')触发器,但结果却是一样的.
有解决方案吗
我有一个表单是一个更新用户表单,其中几个元素是复选框.如果选中(这是正常工作),我想要传递给params,如果未选中(不工作),我希望传递给params.未经检查的项目甚至没有被发送到参数.如何使未经检查的项目通过为假?
形成
<%= form_tag user_url(@user), class: "form-signin", method: 'patch' do %>
<h4>Please confirm your email. We'll only email you if you have notifications.</h4>
<%= email_field_tag :email, current_user.email %>
<h4>Want to be notified when someone needs a player? Choose which sports below.</h4>
<%= check_box_tag :basketball, checked = true %> Basketball</br></br>
<%= check_box_tag :indoor_volleyball, checked = true %> Indoor Volleyball</br></br>
<%= check_box_tag :beach_volleyball, checked = true %> Beach Volleyball</br></br>
<%= check_box_tag :soccer, checked = true %> Soccer</br></br>
<%= check_box_tag :flag_football, checked = …Run Code Online (Sandbox Code Playgroud) 我是Angular2的新手,在全局的web中,我想在检查checkbox和/或取消选中时使用Material-Design,在数据库中启动一个更改oject参数值的操作,我试过[(ngModel)]但没有发生任何事情.这个想法是,我必须添加一些命题与checked | unchecked状态,判断它是一个true或false命题.这是命题模型
export class PropositionModel {
id:string;
wordingP:string; // the proposition
propStatus:Boolean; // the proposition status
}
Run Code Online (Sandbox Code Playgroud)
这是一个命题的Html代码:
<div class="uk-width-xlarge-1-1 uk-width-medium-1-2">
<div (submit)="addProp1()" class="uk-input-group">
<span class="uk-input-group-addon"><input type="checkbox" data-md-icheck/></span>
<label>Proposition 1</label>
<input [(ngModel)]="proposition1.wordingP" type="text" class="md-input" required class="md-input"/>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是用于添加命题的TypeScript代码:
addProp1() {
this.proposition1 = new PropositionModel();
this.proposition1.propStatus = false;
this.propositionService.addProposition(this.proposition1)
.subscribe(response=> {
console.log(response);
console.log(this.proposition1);
this.proposition1 = new PropositionModel();})
}
Run Code Online (Sandbox Code Playgroud)
并且你可以看到我false默认为它做了一个proposition status,我想在检查命题后改变它.这是一个图像如何寻找更好的问题理解.

有什么帮助吗?
想知道是否可以通过按钮改变复选框的大小.我希望它更大,所以它很容易按下.现在它看起来像这样:

码:
<div class="form-group">
<label class="col-md-7 control-label">Kalsiumklorid: </label>
<div class="col-md-5" >
{{ Form::checkbox('O_Kals_Klor', 1 , array('class' => 'form-control' )) }}
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我在我的视图页面上写了以下代码;
@Html.CheckBox("ChxName",true)
Run Code Online (Sandbox Code Playgroud)
我得到了以下结果;
<input checked="checked" id="ChxName" name="ChxName" type="checkbox" value="true" />
<input name="ChxName" type="hidden" value="false" />
Run Code Online (Sandbox Code Playgroud)
为什么有一个与复选框命名相同的输入元素?
<input type="checkbox" name="options[]" value="1" />
<input type="checkbox" name="options[]" value="2" />
<input type="checkbox" name="options[]" value="3" />
<input type="checkbox" name="options[]" value="4" />
<input type="checkbox" name="options[]" value="5" />
Run Code Online (Sandbox Code Playgroud)
如何使用已选中的复选框值创建数组?
注意:(重要)我需要像[1,2,3,4,5]这样的数组,而不是像["1","2","3","4","5"]那样的数组.
注意:大约有50个复选框.
有人能帮我吗?请!
谢谢!
我怎样才能重新使用原来的管理员登录()和AuthenticationForm设置较长的Cookie有效期与"记住我"选项,在登录页面检查用户?我目前正在通过urls.py使用内置登录
url(r'^login/$','django.contrib.auth.views.login', {'template_name': 'authentication/login.html'}, name='login'),
Run Code Online (Sandbox Code Playgroud)
该复选框在我的login.html中实现为:
<label><input name="remember_me" type="checkbox">Keep me logged in</label>
Run Code Online (Sandbox Code Playgroud)
但我不知道如何通过AuthenticationForm传递信息给django.contrib.auth.views.login
目前,如果用户未选中"记住我"框,则会在settings.py中定义cookie年龄
SESSION_COOKIE_AGE = 360
Run Code Online (Sandbox Code Playgroud)
我发现了几个类似的问题,但我认为这不需要安装单独的应用程序.下面的代码片段(http://djangosnippets.org/snippets/1881/)看起来很有希望,但我只编写了几个月的python和Django,但是我无法让它工作:
def login(request, *args, **kwargs):
if request.method == 'POST':
if not request.POST.get('remember_me', None):
request.session.set_expiry(0)
return auth_views.login(request, *args, **kwargs)
Run Code Online (Sandbox Code Playgroud) 使用以下check_box_tag:
<%= check_box_tag 'object[boolean_attribute]', 1, object.boolean_attribute %>
Run Code Online (Sandbox Code Playgroud)
我只能在一个方向更新boolean_attribute:从false到true.
如果默认情况下未选中(因为object.boolean_attribute为false)并且我检查它然后提交表单,则发布a:boolean_attribute => 1参数.
但是,当我尝试从true更新为false时,没有传递param,因此boolean_attribute保持为true.
换句话说,默认情况下检查时(因为object.boolean_attribute为true)并且我取消选中它然后提交表单,则不会发布:boolean_attribute => 0 .
如何取消选中此check_box_tag以发布:boolean_attribute => 0参数?
从api我无法弄清楚是否有一些选项可以轻松实现它:http: //api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-check_box_tag
谢谢.
编辑
出于某种原因,我无法理解,在我的实际代码中(使用嵌套的多对多关联),hidden_field_tag无效.
<%= hidden_field_tag 'order[preparations_attributes][][cooked]', nil %>
<%= check_box_tag 'order[preparations_attributes][][cooked]', '1', preparation.cooked? %>
Run Code Online (Sandbox Code Playgroud)
现在我遇到了相反的问题:我可以取消选中复选框,并按照预期更新准备工作,但是如果我选中复选框,它会使参数更加混乱.
以下是未选中框的已发布参数:
Parameters: {"utf8"=>"?", "authenticity_token"=>"bGgPGbk+Cuk2q+LEgqetmk4e7xie8dB3iMP9Cj3SUm0=", "order"=>{"customer_name"=>"Duccio Armenise", "duedate"=>"2012-04-25 09:24:00.000000", "preparations_attributes"=>[{"quantity"=>"1", "description"=>"custom recipe", "kind"=>"custom", "cooked"=>"", "recipe_id"=>"9", "id"=>"86", "quantities_attributes"=>[{"ingredient_id"=>"", "qty"=>"", "_destroy"=>"0"}, {"ingredient_id"=>"11", "qty"=>"5.0", "id"=>"193", "_destroy"=>"0"}], "_destroy"=>"0"}], "add_preparation"=>{"recipe_id"=>""}}, "continue"=>"Confirm", "id"=>"31"}
Run Code Online (Sandbox Code Playgroud)
现在看看当我检查复选框时出现了一些混乱,从"cooked"=>""开始,出于某种原因,Rails太早关闭了prepare_attributes哈希!
Parameters: {"utf8"=>"?", "authenticity_token"=>"bGgPGbk+Cuk2q+LEgqetmk4e7xie8dB3iMP9Cj3SUm0=", "order"=>{"customer_name"=>"Duccio Armenise", "duedate"=>"2012-04-25 09:24:00.000000", "preparations_attributes"=>[{"quantity"=>"1", "description"=>"custom recipe", "kind"=>"custom", "cooked"=>""}, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Angular 2.0进行简单的操作我希望将模型绑定到"输入复选框",使用方法注册"更改",在复选框状态更改时执行方法并根据模型的状态执行操作.一切正常,但是当执行与change事件链接的方法时,模型的状态与我的预期相反,即当选中该复选框时为false,当取消选中该复选框时为true.这是代码片段;
<input value={{object.name}} type="checkbox" [(ng-model)]="object.selected" (change)="onChange(object.selected)">
Run Code Online (Sandbox Code Playgroud)
关于我做错了什么的任何想法?
checkbox ×10
angular ×2
jquery ×2
arrays ×1
asp.net-mvc ×1
css ×1
data-binding ×1
django ×1
html5 ×1
ios ×1
iphone ×1
laravel-4 ×1
login ×1
params ×1
razor ×1
remember-me ×1
typescript ×1