2017-01-25 7 views
1

私は1つのフィールドでclass = "errorwidth"を使用し、他はclass = "error"を使用するテーブルのコードを持っています。私はこれらのクラスの値を変数に入れたいと思っています。 &これらのクラスの値が異なる数値ここ変数のクラス値を取得する方法は?

<td class="error" style="color:red"></td><td class="errorwidth" style="color:red"></td> 

で表の列に変更し、私はこの1つのクラスのデータを取得しようとしているコードは、「貨物は、20STD、40STDと40HCコンテナに収まらないですあなたはとてもval()あなたのケースでは動作していない、常に値としてテキストを含むtext()divために試してみてください変数

var error = $(this).val(); 
    var errorOnly = ($(this).attr('class') == 'error') ? error : false; 

      var errorwidth = $(this).val(); 
    var errorwidthOnly = ($(this).attr('class') == 'errorwidth') ? errorwidth : false;  

       so that i can use that variables here in this code: 


if (grandTotal > 7 && errorwidthOnly != "Cargo won't fit in 20STD, 40STD and 40HC Containers, change the mode to bulk" && errorOnly != "Cargo won't fit in 20STD, 40STD and 40HC Containers, change the mode to bulk") { 
        $('#result').html('FCL'); 
       } else if (grandTotal < 7 && errorwidthOnly != "Cargo won't fit in 20STD, 40STD and 40HC Containers, change the mode to bulk" && errorOnly != "Cargo won't fit in 20STD, 40STD and 40HC Containers, change the mode to bulk") { 
        $('#result').html('LCL'); 
       } 
       else if((grandTotal > 7 || grandTotal < 7) && errorwidthOnly == "Cargo won't fit in 20STD, 40STD and 40HC Containers, change the mode to bulk" || errorOnly == "Cargo won't fit in 20STD, 40STD and 40HC Containers, change the mode to bulk" || errorOnly != "Cargo won't fit in 20STD and 40STD Containers, change the mode to bulk") 
       { 
       $('#result').html('BULK'); 
      } 
+1

'$( '。errorwidth')。text()'または '$( 'errorwidth').html();'? –

+0

実際に$( '。errorwidth')はテキスト値を持っていますが、grandTotalは数字と小数の両方を持っています。結果は両方とも1つのid( '#result')に表示する必要があります – Ankit

答えて

0

に「バルクにモードを変更します。

var error = $(".error").text();// change here 
    var errorOnly = ($(this).attr('class') == 'error') ? error : false; 

      var errorwidth = $(".errorwidth").text();//Change Here 
    var errorwidthOnly = ($(this).attr('class') == 'errorwidth') ? errorwidth : false;  

       so that i can use that variables here in this code: 


if (grandTotal > 7 && errorwidthOnly != "Cargo won't fit in 20STD, 40STD and 40HC Containers, change the mode to bulk" && errorOnly != "Cargo won't fit in 20STD, 40STD and 40HC Containers, change the mode to bulk") { 
        $('#result').html('FCL'); 
       } else if (grandTotal < 7 && errorwidthOnly != "Cargo won't fit in 20STD, 40STD and 40HC Containers, change the mode to bulk" && errorOnly != "Cargo won't fit in 20STD, 40STD and 40HC Containers, change the mode to bulk") { 
        $('#result').html('LCL'); 
       } 
       else if((grandTotal > 7 || grandTotal < 7) && errorwidthOnly == "Cargo won't fit in 20STD, 40STD and 40HC Containers, change the mode to bulk" || errorOnly == "Cargo won't fit in 20STD, 40STD and 40HC Containers, change the mode to bulk" || errorOnly != "Cargo won't fit in 20STD and 40STD Containers, change the mode to bulk") 
       { 
       $('#result').html('BULK'); 
      } 
+0

申し訳ありません。テーブルフィールド​​に表示されるクラスのエラーとエラー幅の値。 &あなたは私に変数値が正しい値を得ているかどうかをチェックする方法を教えてください。 PHPのように、<?php echo $ variablename?>&このコード行では、値が正しいことを簡単に確認できます。もう一度やり直してください。 よろしくお願いします。Ankit – Ankit

+0

セレクタとしてクラス名を使用するとどうなりますか? @Ankit私のコードを変更しましたので、今すぐお試しください。 –

+0

'var error = $("エラー ")。テキスト();' var errorwidth = $( "errorwidth")。text(); ' –

関連する問題