我正在使用Visual Studio LightSwitch 2015
我已经从SQL Server添加了Countries
表,并且在列表中添加了每个Country
,我有CheckBox
现在我使用CheckBox
将Custom Control
放在列表的顶部
myapp.Countries.CheckAll_postRender = function (element, contentItem) {
var checkbox = $("<input type='checkbox'/>")
.css({
height: 20,
width: 20,
left:-26,
margin: "45px"
})
.appendTo($(element));
};
如何通过单击表格顶部的Select\DeSelect All
来CheckBox
列表中的CheckBoxes?
任何帮助将不胜感激。
虽然上面的代码示例有效,但实际上可以更快地完成它,假设您要检查的复选框是页面上唯一的复选框(除了“全部选中”复选框)。
下面检查页面上的所有复选框,但“全部检查”除外。
$("#checkAll").click(function () {
$('input:checkbox').not(this).prop('checked', this.checked);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" id="checkAll">Check All
<hr />
<input type="checkbox" id="checkItem">Item 1
<input type="checkbox" id="checkItem">Item 2
<input type="checkbox" id="checkItem">Item3
这是Check/Uncheck all the checkboxes in jQuery这个帖子的一个简单例子
$(document).ready(function() {
$('#select-all').click(function(event) {
if(this.checked) {
$('.checkitem').each(function() {
this.checked = true;
});
}else{
$('.checkitem').each(function() {
this.checked = false;
});
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li><label>item-1</label><input name="checkbox-1" id="checkbox-1" type="checkbox" class="checkitem" /></li>
<li><label>item-1</label><input name="checkbox-2" id="checkbox-2" type="checkbox" class="checkitem" /></li>
<li><label>item-1</label><input name="checkbox-3" id="checkbox-3" type="checkbox" class="checkitem" /></li>
<li><label>item-1</label><input name="checkbox-4" id="checkbox-4" type="checkbox" class="checkitem" /></li>
</ul>
<input type="checkbox" name="select-all" id="select-all" /> Check all