行上的jQueryvalidation

我有一个表单需要在我的页面上validation。 表单如下所示: 在此处输入图像描述

我试图找出最好的方法,以确保如果行中的一条信息被填写; 然后需要填写整行。

正如您在示例中所看到的,第3行已经填写了成本但没有标题。 第4行有标题,但没有成本。 我需要在这些类型的东西上抛出错误。

有没有一种简单的方法来实现这一点,以确保是否存在一个数据(在3个可编辑字段中的任何一个),然后整行需要数据。

感谢您的任何意见

可能的方法:

$("#mytable tr").each(function() { var anySet = false, allSet = true; $(this).find("td input").each(function() { var somethingInCell = $(this).val().trim() !== ''; anySet |= somethingInCell; allSet &= somethingInCell; }); if (anySet && !allSet) { // there is missing information } }); 

UPDATE

  $("#mytable").on("input", "input", function(){ var anySet = false, $cells = $(this).closest("tr").find("td input"); $cells.each(function() { var somethingInCell = $(this).val().trim() !== ''; anySet |= somethingInCell; }); $cells.removeClass("has-error"); if (anySet) { $cells.each(function() { if ($(this).val().trim() === '') { $(this).addClass("has-error"); } }); } }); 

你必须手动执行此操作。 我不会为你编写完整的代码,但它会是这样的。

 //on hove of each td $('#tableID tr td').hover(function(){ //loop each its sibling $(this).siblings().each(function( //if any sibling is empty return false if($(this).val().trim() == '') { return false; } )); //else return true return true; });