0

フォームがあり、その中にテーブルがあります。私は次のようなことをしています

function validate(){
var result = true;
$("tr").each(function(){

    if($(this).find(".qty").val()<1||isNaN($(this).find(".qty").val())){
        result = false;
        return false;
    }
    if($(this).find(".pvDetails").text()==""){
         result = false;
         return false;
    }
});

if(result)
    return true;
else
    alert('correct the input values | check your ID or Qty field');
return false;

}

しかし、私のヘッダーは以下のように定義されているので、これは検証のために私のヘッダーも取ります-

<tr height="50px" bgcolor="#EEE8CD">
                    <th align="left" width="10%">Serial No.</th>
                    <th align="left" width="15%">Variant ID</th>
                    <th align="left" width="20%">Product Detail</th>
                    <th align="left" width="17%">Product Image</th>
                    <th align="left" width="10%">B2B Price</th>
                    <th align="left" width="13%">Quantity</th>
                    <th align="left" width="12%">Total</th>
                </tr>

残りは私のテーブル本体です。

私が取っているのと同じアプローチを使用しながら、テーブルヘッダーの検証をスキップするにはどうすればよいですか。

4

2 に答える 2

1

あなたのヘッダーのタグ名は唯一のもので<th>あり、あなたのテーブルコンテンツセルは<td>そうであると思うので、基本的な考え方はあなたの子のタグ名をチェックすることです<tr>

   $("tr").children().each(function () {
    if ($(this).prop("tagName") == "td") {
        if ($(this).find(".qty").val() < 1 || !isNaN($(this).find(".qty").val())) {
            result = false;
            return false;
        }
        if ($(this).find(".pvDetails").text() == "") {
            result = false;
            return false;
        }
    }
   });

<tbody>まあ、別のアイデアは、このようにセクションだけを読んでいるだけです

$("#mytable tbody tr").children().each(function () {

        if ($(this).find(".qty").val() < 1 || !isNaN($(this).find(".qty").val())) {
            result = false;
            return false;
        }
        if ($(this).find(".pvDetails").text() == "") {
            result = false;
            return false;
        }
   });
于 2013-02-13T13:07:14.670 に答える
1

検証したくない行に「skipvalidation」というクラス名を追加します。次に、3 行目を次のように変更します。

$("tr").not('.skipvalidation').each(function(){ ...
于 2013-02-13T13:07:56.043 に答える