2014-02-07 4 views
0

나는이 계산기를 html로 javascript로 만들고있다. 나는 이미 작업하고있다. 그냥 평범한 텍스트로 총을 입력하고 싶다. 지금은 입력 상자가 없다. ...입력란에 총을 쓰지 않고 표시하는 방법은 무엇입니까?

JS 피들은 여기에있다 : 다음

이 ID를 total와 사업부/SPAN 또는 무언가를 만들고 : http://jsfiddle.net/Eliasperez/PDct2/1/

<div>Producto 
<br /> 
<select id="producto1"> 
    <option>Selecciona</option> 
    <option value="01">Curativo</option> 
    <option value="02">Preventiva</option> 
</select> 
</div> 
<table> 
<tbody> 
    <tr class="e01"> 
     <td class="01"> 
      <label>Cantidad</label> 
      <br /> 
      <select id="elias"> 
       <option value="1">1 Gr/m3</option> 
      </select> 
     </td> 
     <td class="02"> 
      <label>Cantidad</label> 
      <br /> 
      <select id="elias1"> 
       <option value=".33">.33 Gr/m3</option> 
      </select> 
     </td> 
    </tr> 
</tbody> 
</table> 
<div class="container"> 
<div> 
    <label for="CAT_Custom_500436">Cual es el volumen del area a tratar por metro  cúbico? </label> 
    <br /> 
    <input type="text" maxlength="255" name="CAT_Custom_500436" id="CAT_Custom_500436" /> 
</div> 
<div> 
    <label for="CAT_Custom_500440">Total</label> 
    <br /> 
    <input type="text" maxlength="255" name="CAT_Custom_500440" id="CAT_Custom_500440" /> 
</div> 
</div> 
<div class="error hide">Porfavor escoje un producto 
</div> 

답변

1
Replace you input <input type = "text" maxlength = "25 name = "CAT_Custom_500440" id = "CAT_Custom_500440"/> 

    with this span: 
    <span id='totalValue'></span> 

    And use this code then: 

$(document).ready(function() { 
// Cache the variables 
    var $elias = $('#elias'), 
     $elias1 = $('#elias1'), 
     $elias2 = $('#elias2'), 
     $product = $('#producto1'), 
     $error = $('.error'), 
     $container = $('.container'); 
    $("td").hide(); 
    var productValue; 
    $product.change(function() { 
     $(".e01 td").hide(); 
     $("td." + $(this).val()).show(); 
     // Only show the container when the selections are not first 2 
     if (this.value !== 'Selecciona' && this.value !== '00') { 
      $error.addClass('hide'); 
      $container.removeClass('hide'); 
     } else { 
      $error.removeClass('hide'); 
      $container.addClass('hide'); 
     } 
     productValue = this.value; 
    }).change(); 
    // Bind the change event for Dropdowns 
    var $quantity = $('#CAT_Custom_500436'), 
     $total = $("#totalValue"); 

    $elias.add($elias1).add($elias2).change(findTotal); 
    $quantity.keyup(findTotal); 

    function findTotal() { 
     // Get the value 
     var quan = $quantity.val(); 
     var pri = $('.' + productValue).find('select').val(); 
     var tot = pri * quan; 
     var toto = tot + " Gr de Fumispore"; 
     $total.text(toto); 
    } 
    }); 
0

당신은 요소를 선택하고 텍스트로 총을 설정할 수 있습니다

$('#total').text(total);

+0

단지 하나의 요소 인 경우 클래스가 아닌 ID를 사용해야합니다. – Barmar

+0

나는 div로 작성한 ID를 가지고 div를 만들었고 코드는 내가 만든 javascript를위한 것입니까? 너무 많이 문제가되지 않으면 이미 잃어버린 메신저부터 jsfiddle를 통해 나를 모범으로 삼을 수 있습니까? –

+0

총계를 정의하는 위치에 위 코드를 추가하십시오. 코드 스 니펫은 합계를 취하여'# total' div의 텍스트 값으로 설정합니다. – helion3

관련 문제