jQuery Part 2
2015-09-21 01:37
816 查看
1. html 和 js 传值
html:
@(lang: String, shop: Shop, meal: Meal, table: DiningTable)
@layout("Dashboard", Seq("/assets/javascripts/operator-dashboard.min.js"), Seq("/assets/stylesheets/operator-dashboard.min.css")){
<script>
window.id = @meal.id;
</script>
注意 在html中传入的值需要加@取值,不能直接传对象并使用,例如meal,因为这时对象只是一个特定字符串,但是可以单独取元素使用.
javascript:
id = window.id
可以直接用window传递值
2. js 实时检测输入变化, 如下 输入subtotal discount, Total实时变化
Subtotal:
Discount:
Total: $0.00
displayInvoice = (subtotal, discount) ->
discountAmount = subtotal*discount/100
$('.display-discount').html "$" + discountAmount.toFixed(2)
total = 0
total = subtotal
total -= discountAmount
$('.display-total').html "$" + total.toFixed(2)
updateInfo=() ->
subtotal = parseFloat($('#subtotal').val())
discount = parseFloat($('#discount').val())
if !subtotal
subtotal = 0
if !discount
discount = 0
displayInvoice(subtotal,discount)
$(document).ready ->
$('.btn-pay').on('click', ->
payMeal(window.id)
)
$('#subtotal').on('keyup', ->
updateInfo()
)
$('#discount').on('keyup', ->
updateInfo()
)
$('.input-gst').on('click', ->
updateInfo()
)
html:
@(lang: String, shop: Shop, meal: Meal, table: DiningTable)
@layout("Dashboard", Seq("/assets/javascripts/operator-dashboard.min.js"), Seq("/assets/stylesheets/operator-dashboard.min.css")){
<script>
window.id = @meal.id;
</script>
注意 在html中传入的值需要加@取值,不能直接传对象并使用,例如meal,因为这时对象只是一个特定字符串,但是可以单独取元素使用.
javascript:
id = window.id
可以直接用window传递值
2. js 实时检测输入变化, 如下 输入subtotal discount, Total实时变化
Subtotal:
Discount:
Total: $0.00
displayInvoice = (subtotal, discount) ->
discountAmount = subtotal*discount/100
$('.display-discount').html "$" + discountAmount.toFixed(2)
total = 0
total = subtotal
total -= discountAmount
$('.display-total').html "$" + total.toFixed(2)
updateInfo=() ->
subtotal = parseFloat($('#subtotal').val())
discount = parseFloat($('#discount').val())
if !subtotal
subtotal = 0
if !discount
discount = 0
displayInvoice(subtotal,discount)
$(document).ready ->
$('.btn-pay').on('click', ->
payMeal(window.id)
)
$('#subtotal').on('keyup', ->
updateInfo()
)
$('#discount').on('keyup', ->
updateInfo()
)
$('.input-gst').on('click', ->
updateInfo()
)
相关文章推荐
- jquery $.proxy使用
- jQuery实现响应鼠标滚动的动感菜单效果
- 基于jQuery实现多层次的手风琴效果附源码
- jQuery+HTML5美女瀑布流布局实现方法
- 基于JQuery和CSS3实现仿Apple TV海报背景视觉差特效源码分享
- jQuery实现Tab菜单滚动切换的方法
- jQuery的parent和parents和closest区别
- 如何通过js和jquery获取图片真实的宽度和高度
- jQuery.extend 函数详解
- jQuery源码学习 之 类数组对象结构 ---- day3
- 【jQueryMobile】Helloworld而页面切换
- jquery动态添加以及遍历option并获取特定样式名称的option
- 使用Jquery+EasyUI 进行框架项目开发案例讲解之五 模块(菜单)管理源码分享
- 使用Jquery+EasyUI 进行框架项目开发案例讲解之四 组织机构管理源码分享
- 【笔记】jQuery基础课程(慕课)(上)
- jQeury插件 - 图片剪切器 (jQuery.jCutter)
- 关于 jQuery 中的 $.data() 方法和 jQuery 对象上的data 方法
- jQuery.Deferred(func)总结
- js、jQuery中常用的一些方法
- 解决jquery操作checkbox火狐下第二次无法勾选问题