jquery 高亮应用大量,如何避免它
我正在做一个预订火车座位的网站。 该表格需要一个价格计算器来向客户显示总金额 当他/她选择服务、乘客数量等时。
为了使总成本的变化更加明显,我在div上使用了jq突出效果,只是为了获得更多关注。
问题是当滑块滑动时我让它突出显示,所以如果我从 0 到 56(火车车厢的最大座位),突出显示会出现 56 次。
希望您能提供帮助,或者提出更好的想法。
代码如下:
$(document).ready(function(){
/**/
function calculateTotal(){
//var unitPrice = 2, paperTypes = 2, printedSides = 2;
var precio_base = $('#categoria option:selected').val();
var cant_adultos = $("#adultos").val();
var cant_ninos = $("#ninos").val();
var sum = parseInt(cant_adultos) + parseInt(cant_ninos);
var precio_productos = $("input[name^='servicio']").parseNumber();
var totalCost = parseInt(precio_base)*parseInt(sum);
$('#total-box').html("$"+totalCost);
$('#total-box').effect("highlight", {}, 1000);
}
$('#categoria,#adultos,#ninos').change(calculateTotal).highlight();
});
该页面位于 http: //www.micontrol.cl/~mvargas/wordpress/wp-transatacama/reservas-rapidas/form-reservas.php。
I'm doing a website for reserving seats on a train.
The form needs a calculator for the price to show the client a total amount
while he/she is selecting service, quantity of passengers, etc.
To make more obvious the change in the total cost I used the jq highlight effect on the div, just to get more attention.
The problem is that I had it highlight when a slider slides, so if I pass from 0 to 56 (max seats on the train wagon) the highlight occurs 56 times.
Hopefully you could help out, or suggest a better idea.
Here's the code:
$(document).ready(function(){
/**/
function calculateTotal(){
//var unitPrice = 2, paperTypes = 2, printedSides = 2;
var precio_base = $('#categoria option:selected').val();
var cant_adultos = $("#adultos").val();
var cant_ninos = $("#ninos").val();
var sum = parseInt(cant_adultos) + parseInt(cant_ninos);
var precio_productos = $("input[name^='servicio']").parseNumber();
var totalCost = parseInt(precio_base)*parseInt(sum);
$('#total-box').html("$"+totalCost);
$('#total-box').effect("highlight", {}, 1000);
}
$('#categoria,#adultos,#ninos').change(calculateTotal).highlight();
});
The page is at http://www.micontrol.cl/~mvargas/wordpress/wp-transatacama/reservas-rapidas/form-reservas.php.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您正在使用 jQuery UI 中的滑块小部件(jQuery UI 似乎包含在您链接到的页面上),您可以绑定到
停止
事件而不是更改
。像这样的东西:Assuming you're using the slider widget from jQuery UI (jQuery UI appears to be included on the page you linked to), you could bind to the
stop
event instead ofchange
. Something like this:您需要停止在每个幻灯片步骤上触发更改事件。
只需在停止事件上触发即可。例如:http://jsbin.com/atolax/2
You need to stop triggering the change event on every slide step.
Just trigger that on stop event. ex: http://jsbin.com/atolax/2