2017-01-25 2 views
1

나는 하나의 필드에서 class = "errorwidth"를 사용하고 다른 클래스는 "error"인 테이블 코드를 가지고있다. 변수에서이 클래스 값을 가져 오려고합니다. & 이러한 클래스의 값은, 여기에 내가 클래스 데이터가 "화물 20STD, 40STD 및 40HC 컨테이너이 하나 들어 가지 않는 얻기 위해 노력하고있어 코드는 다른 숫자 값변수에서 클래스 값을 가져 오는 방법은 무엇입니까?

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

으로 테이블 컬럼에 변경 당신은 너무 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은 숫자/십진수 값을 가지고 있으며 하나의 단일 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

죄송합니다. 코드는 변경하지만 작동하지 않습니다. 테이블 필드 에 표시된 클래스 오류 및 오류 폭 값. & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; 나는 변수 값이 올바른 값인지 아닌지를 어떻게 확인할 수 있는지 알려주실 수 있습니까 PHP에서와 같이 우리는 &이 코드를 사용하여 우리의 값이 정확한지 쉽게 확인할 수 있습니다. 다시 시도하십시오 감사합니다 Ankit – Ankit

+0

선택자로 클래스 이름을 사용하면 어떻게됩니까? @Ankit 내 코드가 바뀌므로 지금 시도하십시오. –

+0

'var error = $ ("."오류) text();'var errorwidth = $ (". 오류 폭") text();' –

관련 문제