Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jquery基于另一个字段验证一个字段_Jquery - Fatal编程技术网

如何使用jquery基于另一个字段验证一个字段

如何使用jquery基于另一个字段验证一个字段,jquery,Jquery,我有一张桌子 <table> <tr class ="entry1"> <td class = "my_cell" name ="point" > <td class = "my_cell" name ="distance1" > <td class = "my_cell" name ="distance2" > </tr> <tr class ="entry2"> <t

我有一张桌子

<table>
  <tr class ="entry1">
  <td class = "my_cell" name ="point" >
  <td class = "my_cell" name ="distance1" >
   <td class = "my_cell" name ="distance2" >
   </tr>

   <tr class ="entry2">
  <td class = "my_cell" name ="point" >
  <td class = "my_cell" name ="distance1" >
   <td class = "my_cell" name ="distance2" >
   </tr>

</table>

如果填写了名为“distance1”或“distance2”的任何字段,则应填写同一行(不在另一行)中名为“point”的相应文本框,否则应打印错误消息

如果填写了名为“point”的文本字段,则应填写同一行中相应的测试框“distance1”或“distance2”(不在另一行),或者必须打印类似的错误消息

$('input[name=distance1], input[name=distance2]').change(function() {
    if (this.value != "") {
        $(this).closest('tr').find('[name=point]').val(filling); //whatever the value should be
    } else {
        // show error message
    }
});
它并非完美无瑕,您可能需要比此更好的检查。value

在编辑之后(我假设输入,现在不那么动态):


这只运行一次,您需要为点异常执行类似的操作。但它还不够具体,无法立即创建。

您的问题是什么?似乎您正在寻找代码。相反,你可能想展示你所拥有的,这样我们就可以帮助你卡在哪里。我有一个表,这个问题的部分没有显示,请考虑上面的问题的例子,我为你修正了代码格式化。您需要用4个空格缩进代码块。看,谢谢,我会利用itI,我假设你们有输入,这可能,td上的名字有点奇怪。编辑之后,我想你还想要点别的。。给我一分钟。
$('table tr').each(function() {
     var row = $(this);
     if (row.find('[name=distance1]').text() != "" || row.find('[name=distance1]').text() != "") {
          row.find('[name=point]').text(filling); //whatever you want to set
     } else {
          // show error message
     }
});