使用 onblur 乘以 <g:field> grails

use onblur to multiplicar <g:field> grails

嗨我想将我的框的值乘以一个十进制值并用onblur将它显示在其他文本框中。

<script type="text/javascript">
$(document).ready(function () {
    $("#Agregar") {
        var pred = $("#predis").val();

        var result = parseFloat(pred) * 0.15;


        $("#pagoTotal").val(result);
    });
});

</script>

问题是函数什么都不做

<g:field name="predis" id="predis" type="number" onblur="Agregar()" value="${predisInstance.predis}" required=""/>
<g:field name="pagoTotal" id="pagoTotal" type="number" value="${pagoTotalInstance.pagoTotal}"   required=""/>

实际上您没有 grails 问题。这是一个 javascript 问题。按名称获取输入。

(function($){
 $(document).ready(function(){
   $('input[name="predis"]').on('blur', function(){
     agregar($(this));
    });
  });
  
  function  agregar(predis){
   var predis = $(predis);    
    var pred = predis.val();
    var result = parseFloat(pred) * 0.15;
    $('input[name="pagoTotal"]').val(result);
  }
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<!--The <g:field ...> tags would parse to something similar to the following hmtl   -->
<input name="predis" id="predis" type="number"  value="0" required=""/>
<input name="pagoTotal" id="pagoTotal" type="number" value="0"   required=""/>