【发布时间】:2016-06-28 16:13:41
【问题描述】:
我有一个简单的表,其中包含 3 列,其中 classes = "code","description","delete" 该列的 class "delete" 是一个复选框类型,一个按钮为 class="savebtn"。
我需要以下内容:
当用户点击保存时:
- Jquery 必须验证它有数据的代码列。
- 如果选中删除列中的任何单元格,则删除该行。
- 如果用户检查了删除列警告消息中的所有单元格,表格必须至少有一行,并且不要删除这些行。
这是Demo,但它不适用于我。
我尝试过的:
$(document).ready(function (){
$(".savebtn").bind("click", function(e){
$('.savebtn').attr('disabled',true);
$('.table tbody tr').each(function () {
$(this).find('.code input').each(function () {
if ($(this).closest("tr").find(".delete input").is(":checked") && $('.cf-table-block tbody tr').length >=1){
$('.delete input :checkbox:checked').closest('tr').remove();
$('.savebtn').removeAttr('disabled');
}else if($(this).closest("tr").find(".delete input").is(":checked") && $('.cf-table-block tbody tr').length <2){
e.preventDefault();
}else if($('.delete input').prop('checked')==false && ( $(this).val().length>0)){
$('.savebtn').removeAttr('disabled');
}else if ($('.delete input').prop('checked')==false && ( $(this).val().length==0)){
$(this).attr("placeholder", "Please fill this field");
}
});
});
});
});
【问题讨论】:
-
(index):45 Uncaught ReferenceError: $ is not defined- 没有 jQuery 参考。 -
查看demo
标签: javascript jquery