你怎么可以添加25,当您检查框,并减去25如果没有选择它是跨度ID =里面“preciototal”多少?如何添加在检查和不检查的使用jquery subract
看看这里吧。 其检出形式的一部分,这个想法是它计算总价:
你怎么可以添加25,当您检查框,并减去25如果没有选择它是跨度ID =里面“preciototal”多少?如何添加在检查和不检查的使用jquery subract
看看这里吧。 其检出形式的一部分,这个想法是它计算总价:
作为向您演示一些更高级jQuery概念的替代答案,请考虑以下javascript:
$(document).ready(function() {
// cache anything reused in variables
var $zonaenvio = $("#zonaenvio");
var $gelypilas = $('#gelypilas');
var $totalprecio = $('#totalprecio');
var $totalSpan = $('#preciototal');
// declare a function that does everything
var updatePrice = function() {
// get the value of the selected product, or 0 if nothing selected
var productAmount = parseInt($zonaenvio.val() || '0');
if (productAmount > 0) {
// if something selected, calculate correct total and show it
var correctTotal = productAmount + ($gelypilas.is(':checked') ? 25 : 0);
$totalSpan.text(correctTotal);
$totalprecio.show('slow');
} else {
// otherwise, if nothing selected, hide the total information
$totalprecio.hide();
}
};
// bind the function to the input events
$zonaenvio.change(updatePrice).change(); // trigger once if needed
$gelypilas.change(updatePrice);
});
这有道理吗?请参阅here以了解正在运行的jsFiddle示例。
的伟大!但还有一个子问题。你还将如何将最终值添加到输入值? 比方说一共是400,我需要把400在输入的值=“这里”监守这就是那个被发布到结账服务 – sebas
http://jsfiddle.net/9YGBu/15/它有助于价格? ? – renatoargh
肯定是的,谢谢! – sebas
也许这样的事情,我缓存选择优化:
$(document).ready(function() {
var precioTotal = $("#preciototal"), gelypilas = $('#gelypilas'),
totalPrecio = $('#totalprecio'), zonaEnvio = $("#zonaenvio");
zonaEnvio.change(function() {
precioTotal.text($(this).val());
gelypilas.removeAttr('checked');
totalPrecio.show("slow");
}).change(); // trigger once if needed
gelypilas.change(function(){
if(gelypilas.attr('checked')){
precioTotal.text(parseInt(precioTotal.text()) + 25);
}else{
precioTotal.text(Math.max(0, parseInt(precioTotal.text()) - 25));
}
});
});
我喜欢这个...很多 – sebas