大佬教程收集整理的这篇文章主要介绍了Yii2-dynamicforms和javascript,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<?PHP $script = <<< JS $('#itemsfactura-{$i}-cantidad').change(function(){ var cantidad = $(this).val(); var precio = $('#itemsfactura-{$i}-precio').val(); $('#itemsfactura-{$i}-@R_862_10586@l_item').val(cantidad * precio); }); JS; $this->registerJs($script); ?>
这是动态表单字段的代码:
... <div class="row"> <div class="col-sm-4"> <?= $form->field($modelItemFactura,"[{$i}]precio")->texTinput(['maxlength' => true]) ?> </div> <div class="col-sm-4"> <?= $form->field($modelItemFactura,"[{$i}]cantidad")->texTinput(['maxlength' => true]) ?> </div> <div class="col-sm-4"> <?= $form->field($modelItemFactura,"[{$i}]@R_862_10586@l_item")->texTinput(['maxlength' => true]) ?> </div> </div>...
<div class="col-sm-4"> <?= $form->field($modelItemFactura,"[{$i}]precio")->texTinput(['maxlength' => true,'onchange' => 'getProduct($(this))','onkeyup' => 'getProduct($(this))']) ?> </div> <div class="col-sm-4"> <?= $form->field($modelItemFactura,"[{$i}]cantidad")->texTinput(['maxlength' => true,'onkeyup' => 'getProduct($(this))']) ?> </div>
JS
function getProduct(item) { var index = item.attr("id").replace(/[^0-9.]/g,""); var @R_862_10586@l = current = next = 0; var id = item.attr("id"); var myString = id.split("-").pop(); if(myString == "precio") { fetch = index.concat("-cantidad"); } else { fetch = index.concat("-precio"); } temp = $("#itemsfactura-"+fetch+"").val(); if(!isNaN(temp) && temp.length != 0) { next = temp; } current = item.val(); if(isNaN(current) || current.length == 0) { current = 0; } if(!isNaN(current) && !isNaN(next)) { @R_862_10586@l = parseInt(current) * parseInt(next); } @R_862_10586@lItem = "itemsfactura-".concat(indeX).concat("-@R_862_10586@l_item"); $("#"+@R_862_10586@lItem+"").val(@R_862_10586@l); }
以上是大佬教程为你收集整理的Yii2-dynamicforms和javascript全部内容,希望文章能够帮你解决Yii2-dynamicforms和javascript所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。