Last active
October 23, 2018 07:40
-
-
Save wisaruthk/6608014eec52dcfac3471f5fd047e780 to your computer and use it in GitHub Desktop.
การใช้ <script> ใน yii2 view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ปกติการ ใช้ registerJs("") ของ yii2 จะทำให้การเขียน script ค่อนข้างยาก | |
* ดังนั้นจึงเขียน javascript ในลักษณะนี้จะจัดการได้ง่ายกว่า ไม่ต้องคอยกังวลกับปัญหา "", '' | |
*/ | |
<script type="text/javascript"> | |
var obj = { | |
init:function(){ | |
$('#po-product_uom_qty').on('change',function(e){ | |
obj.calculateAmount(); | |
}); | |
$('#po-price_unit').on('change',function(e){ | |
obj.calculateAmount(); | |
}); | |
}, | |
calculateAmount:function(){ | |
var qty = $("#po-product_uom_qty").val(); | |
var price_unit = $("#po-price_unit").val(); | |
var amount = qty*price_unit; | |
$("#po-amount").val(amount); | |
} | |
} | |
</script> | |
<?php | |
$this->registerJs(" | |
$(document).ready(function(){ | |
obj.init(); | |
}); | |
",View::POS_READY); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment