嗨我想将我的方框的值乘以十进制值,并在其他文本框中显示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=""/>
答案 0 :(得分:1)
其实你没有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=""/>