我有一个表格,每行开头都有一个复选框.每个复选框都具有#tablecheckbox的ID.表标题行有一个检查图标,应该检查表中的所有框.我怎么能用jQuery做到这一点?
我有一个总是被选中的复选框,但基于用户输入我的表单中的其他地方(我有onChange="functionName"一个选择框)我想取消选中它.
我怎么做?
我正在从jQuery 1.5.1升级 - 我已经阅读了关于"检查"复选框(在1.6中)的"新"方法
prop("checked", true);
Run Code Online (Sandbox Code Playgroud)
但删除复选框的正确/首选方法是什么?
这两种方法似乎都有效
$('#someSelector').removeProp("checked");
Run Code Online (Sandbox Code Playgroud)
要么
$('#someSelector').prop("checked", false);
Run Code Online (Sandbox Code Playgroud)
这些方法之间有区别吗?我应该使用哪个?
谢谢
在下面的代码中使用jQuery:
$("input").change(function(evt) {
console.log("change event handler invoked", evt);
console.log($("input").is(':checked'));
console.log($("input").attr("checked"));
console.log($("input").prop("checked"));
});
$("input").trigger("click");
$("input").trigger("click");Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<input id="the-input" type="checkbox">Run Code Online (Sandbox Code Playgroud)
在is(':checked')与prop("checked")都能表现出一个真实的,但'ATTR("选中")将显示不确定的.我以为他们是一样的?(即使我们手动点击复选框,也会产生相同的效果).
另外,如果我checked在HTML中设置默认情况下选中复选框(http://jsfiddle.net/UcGyM/1/),现在attr("checked")将打印出checked两个触发器,因此它无法判断是否是否检查 - 为什么?(这两个节目也很奇怪checked,但$("input").attr("checked", true);也$("input").attr("checked", false);可以打开或关闭.)
一个相关的问题是,如果我们想要坚持使用attr("checked"),这是否意味着在HTML中,它必须具有以下checked属性:<input type="checkbox" checked>如果是,它如何指定属性但是默认为关闭?(因为checked="false"或者checked=""或者checked="0"不会让选择它的默认值.
大家好,这个任务似乎很容易,虽然我的代码不起作用.
我有一些行的表,每行有一个复选框,在下面我把按钮"全部删除"取消选中复选框.这是我的代码:
$('#remove-button').click(function(){
$('input:checked').prop('checked',false);
//e.stopPropagation(); // I tried also with this
// $('input:checked').removeAttr('checked'); // or this syntax
});
Run Code Online (Sandbox Code Playgroud)
当我点击按钮时,所有输入都是未选中的,但由于我的代码不会发生这种情况,因为当我评论此片段时,当我点击按钮时也会发生这种情况.我也看到,当我点击并且输入未被选中时,我的网站似乎刷新了,因为页面空洞.
我还添加了另一个按钮来检查输入:
$('#add-button').click(function(e){
$('input').prop('checked',true);
//e.stopPropagation(); // I tried also with this
// $('input:checked').removeAttr('checked'); // or this syntax
});
Run Code Online (Sandbox Code Playgroud)
当我点火这个输入被检查,一秒钟我的网站刷新,一切都消失了.
我使用最新的Firefox和Chrome,以及jQuery - 1.11(但也检查了1.8.0和1.7.1).还有一些问题
谁知道什么是错的?
我有以下 GridView:
<asp:GridView ID="gvSpecificRights" runat="server" AutoGenerateColumns="false" OnRowCreated="gvSpecificRights_RowCreated" CssClass="mGrid" ShowHeaderWhenEmpty="true" ShowFooter="true">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
<asp:TemplateField HeaderText="Name">
<ItemTemplate><asp:Label ID="lblName" runat="server" Text='<%# Bind("Name") %>'></asp:Label></ItemTemplate>
<FooterTemplate><asp:DropDownList ID="ddlAvailableUsers" runat="server"></asp:DropDownList></FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Create" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center">
<ItemTemplate><asp:CheckBox ID="cbTickCreator" runat="server" Checked='<%# Eval("TickCreator") %>' CssClass="clicknext"></asp:CheckBox></ItemTemplate>
<FooterTemplate><asp:CheckBox ID="cbFooterTickCreator" runat="server" CssClass="clicknext"></asp:CheckBox></FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Read" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center">
<ItemTemplate><asp:CheckBox ID="cbTickViewer" runat="server" Checked='<%# Eval("TickViewer") %>'></asp:CheckBox></ItemTemplate>
<FooterTemplate><asp:CheckBox ID="cbFooterTickViewer" runat="server"></asp:CheckBox></FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnSave" runat="server" Text="<i class='fa fa-floppy-o'></i>" OnClick="btnSave_Click" CommandArgument='<%# Eval("ID")%>'/>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="btnAdd" runat="server" Text="<i class='fa fa-plus'></i> Hinzufügen" OnClick="btnAdd_Click" /> …Run Code Online (Sandbox Code Playgroud) 我有一个带有复选框列表的表单.我想创建一个checkAll和UncheckAll框以获得更好的用户体验.我尝试了很多从Internet获得的代码,但没有一个能够工作.你能帮我看看,告诉我是什么问题.谢谢
<script type="text/javascript">
function checkAll(field)
{
for (i = 0; i < field.length; i++)
field[i].checked = true ;
}
function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
field[i].checked = false ;
}
</script>
<style type="text/css">
#user_info {
border-collapse:collapse;
}
#user_info td, #user_info th {
width:100px;
border:1px solid #CACACA;
padding:5px;
}
#checkbox{
padding:20px 0 20px 250px;
}
</style>
<p>Please choose all the users whose group_id you want to replace with that of the uploaded file</p>
<form id="groupImportForm" action="<?php …Run Code Online (Sandbox Code Playgroud) <select name="status" id='status'>
<option value="Submitted">Submitted</option>
<option value="Canceled">Canceled</option>
</select>
<input type="checkbox" id="app_box" name="application_complete" value="checked"> App Complete
<script type="text/javascript">
$(function() {
$('form.editable').submit(function(){
if ($('#status').val()=='Canceled') {
if (!confirm('This information will be discarded! )) {
return false;
}
}
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
所以,我有上面的脚本工作正常.我还要再添一个确认.当代理点击提交按钮时,我想检查是否选中了应用程序复选框.如果未选中,则显示另一个确认框,说明您必须选中该复选框.怎么能在jquery中完成.
有一个CheckBox和Button,我想单击Button来检查并取消选中checkBox而不触及checkBox.怎么做 ???
<input type = "checkbox" id = "check" />
<input type = "button" id = "buttonId" />
<script type = "text/javascript">
$(function() {
$("#buttonId").click( function() {
if( $("#check").is_NOT_CHECKED) {
CHECKED_CheckBox;
} else
if($("#check").is_CHECKED) {
UnCHECKED_CheckBox;
}
});
</script>
Run Code Online (Sandbox Code Playgroud) 我有以下HTML:
<form name="smform" id="smform" method="post" action="">
<input type="checkbox" name="Check_All" onClick="Check(document.smform.check)" >
<input type="checkbox" name="check" value="blue_color"> Blue<br>
<input type="checkbox" name="check" value="green_color"> Green<br>
<input type="checkbox" name="check" value="orange_color"> Orange<br>
</form>
Run Code Online (Sandbox Code Playgroud)
有了这个JS:
function Check(chk)
{
if(document.smform.Check_All.checked){
for (i = 0; i < chk.length; i++)
chk[i].checked = true ;
document.smform.Check_All.checked = true;
}else{
for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
document.smform.Check_All.checked = false;
}
}
Run Code Online (Sandbox Code Playgroud)
这个工作正常,我可以选择或取消选中所有复选框,但为了将其作为ARRAY发布,我的复选框将具有以下内容name="check[]":
<input type="checkbox" name="check[]" value="blue_color"> Blue<br>
<input type="checkbox" name="check[]" value="green_color"> Green<br>
<input type="checkbox" …Run Code Online (Sandbox Code Playgroud)