Php 输入单选按钮更改算法
商店。推车Php 输入单选按钮更改算法,php,jquery,html,algorithm,loops,Php,Jquery,Html,Algorithm,Loops,商店。推车 name | price | count | price*count apple 2 2 4 banana 3 4 12 Delivery (radio button) none | checked (radio button) to home (+3) (radio button) to another town (+6) Tota
name | price | count | price*count
apple 2 2 4
banana 3 4 12
Delivery
(radio button) none | checked
(radio button) to home (+3)
(radio button) to another town (+6)
Total Count | 16
- 更改计数时-我的脚本使用Jquery total count text()动态重新计算总计数和更改
到主页
,总计数+=3,那么如果我更改项目的计数
,总计数+=((价格*新计数)-价格*计数)
但当我将配送更改为另一个城镇时,总计数+=(新输入-上一输入电台),但当我更改回0时,总计数-=(输入值)
我的JQuery脚本只需在更改时获取price*count
的值,将price
和count
的兄弟值相乘并检查-如果它不同,则更改总计数文本
var updating = false;
if(!updating){
updatePrice();
}
function updatePrice(){
var pricewas = pricecountitem.text();
var pricenow = pricecount;
var difference = pricenow - pricewas;
var numadd = 1;
if(difference < 0){
pricecountitem.text(+pricewas - numadd);
}else if(difference > 0) {
pricecountitem.text(+pricewas + numadd);
}
if(difference !== 0){
updating = true;
setTimeout(updatePrice, 1000);
}else{
updating = false;
}
}
var更新=false;
如果(!正在更新){
updatePrice();
}
函数updatePrice(){
var pricewas=pricecountitem.text();
var pricenow=pricecount;
var差异=pricenow-pricewas;
var numadd=1;
如果(差异<0){
文本(+pricewas-numad);
}否则,如果(差异>0){
pricecountitem.text(+pricewas+numad);
}
如果(差异!==0){
更新=真;
setTimeout(updatePrice,1000);
}否则{
更新=假;
}
}
我只是不能写算法如何动态地改变价值,包括所有情况下的交付和计数的变化
我的头要爆炸了,你们能帮帮我吗?在下一页添加了交付,在那里输入信息。问题结束。为什么要计算差异?你不能简单地重新计算整个价格,然后改变它吗?只要显示正确的值,价格变化是否重要?您也可以存储小计(无交付)并在更改时简单地重新计算总数(小计+交付)。这并不提供问题的答案。要评论或要求作者澄清,请在他们的帖子下方留下评论——你可以随时对自己的帖子发表评论,一旦你有足够的评论,你就可以发表评论了。