我有以下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) 我正在写一个基本的脚本,我似乎无法理解为什么它不起作用.基本上,如果选中了一个复选框,脚本将锁定所有复选框,如果用户决定取消选中该复选框,则会解锁它们.
这是代码
//Script for questions where you check one option or the other (locks other options out)
$('.optionBox input').click(function(){
var optionBoxElement$ = $(this).closest('.optionBox');
//If no option is checked, the make all the options available to be selected
//Otherwise, one option must be checked so lock out all other options
if(optionBoxElement.find('input:not(:checked)').length == optionBoxElement.find(':input').length)
optionBoxElement.find(':input').prop('disabled',false);
else
optionBoxElement.find('input:not(:checked)').prop('disabled',true);
optionBoxElement.find('input:checked').prop('disabled',false); //makes sure that the checkbox that was checked is not disabled so the user can uncheck and change his answer
});
Run Code Online (Sandbox Code Playgroud) 有没有办法或可以使用javascript/jQuery做到这一点?
基于链接的URL:第一个将检查类型A和类型B,第二个示例将检查类型D.
?type=A&type=C or ?type=D
Run Code Online (Sandbox Code Playgroud)
我目前的表格:
<form name="input" action="" method="post" ><br />
Select Type: <br />
<input type="checkbox" name = "type" value="A" /> A <br />
<input type="checkbox" name = "type" value="B" /> B <br />
<input type="checkbox" name = "type" value="C" /> C <br />
<input type="checkbox" name = "type" value="D" /> D <br /> <br />
<input type="submit" value="Submit" />
Run Code Online (Sandbox Code Playgroud)
有任何提示并建议这样做吗?
我需要查看是否检查了字段集中某个范围内的任何复选框
<fieldset id="issues">
<input name="A" id="issue_0" type="checkbox" value="A" /> <--- this one
<input name="B" id="issue_1" type="checkbox" value="B" />
<input name="C" id="issue_2" type="checkbox" value="C" />
<input name="D" id="issue_3" type="checkbox" value="D" />
<input name="E" id="issue_4" type="checkbox" value="E" />
</fieldset>
Run Code Online (Sandbox Code Playgroud)
字段集是#issues,这可以很好地查看是否有任何一个被检查
if( $('#issues input[type="checkbox"]').is(':checked') ){
console.log("One of them is checked");
}
Run Code Online (Sandbox Code Playgroud)
但我想看看是否检查了索引的特定复选框,即是否检查了第一个复选框.我试过这个......
if( $('#issues input[type="checkbox"][0]').is(':checked') ){
console.log("Item one is checked");
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用
如何通过字段集中的索引来定位特定复选框?
现在当它第一次加载html页面时,我的复选框就是这样创建的:
<input type="checkbox" id="CBOX1" name="CBOX1" onclick="onCBOX(this)" disabled/>
Run Code Online (Sandbox Code Playgroud)
在同一个html中的函数中:
boolean checked = true;
document.theForm.elements['CBOX1'].checked = true;
Run Code Online (Sandbox Code Playgroud)
出于某种原因,在稍后在页面上调用该函数时,不会检查复选框值.是因为当我第一次创建复选框时,我创建了它而没有"已检查"属性?然后当我为它分配一个值时,该元素似乎不再包括checked属性,就像我检查页面的来源一样.它还是一样的......
<input type="checkbox" id="CBOX1" name="CBOX1" onclick="onCBOX(this)" disabled/>
Run Code Online (Sandbox Code Playgroud)
为简单起见,我确信使用AJAX对此元素的其他属性进行了更改,但我不知道为什么检查属性没有被转移...有什么替代方案?
单击"问题"时,两个复选框都必须选中/取消选中.我想多次选择和取消选中复选框.它仅适用于选择然后取消选择(2次),然后不再工作.

我的代码:
$(document).ready(function() {
$('#CHECK-ALL').click(function() {
if ($(this).is(':checked')) {
$('#P').attr('checked',true);
} else {
$('#P').attr('checked',false);
}
});
});
Run Code Online (Sandbox Code Playgroud) 我尝试了一切,没有任何作用.我有这个复选框
<input type="checkbox" onchange="WriteFormSelections('SearchForm', 'AccommodationType', 'AccommodationTypeSelections', 'All', 'AccommodationType-0', false, '_', true);" value="Hotel" name="AccommodationType_Hotel" id="AccommodationType-2">Hotel
Run Code Online (Sandbox Code Playgroud)
我想在页面加载时检查它.我尝试了很多东西.我无法解决的一件事是,我应该使用复选框的ID或名称来检查它吗?
这是我目前的代码.我试图按照这篇文章的建议使用道具,但这也不起作用.
<script type="text/javascript">
$('AccommodationType-2').attr('checked', true);
</script>
Run Code Online (Sandbox Code Playgroud) 这不适用于jQuery 1.9
$("#" + IDProduct).attr("checked", "checked").checkboxradio("refresh");
Run Code Online (Sandbox Code Playgroud)