Javascript 自动填写计算表
我有一个关于产品的例子,当选择一个选项时,输入价格自动填入数据价格,然后在输入数量中输入数量,最后在输入总和中输入价格*数量的结果。如何在更改输入和选择时求和 $'product'.changefunction{ var price=parseInt$this.childrenoption:selected.attrdata-price; $price.attrvalue,price; }; $“数量”。在“输入属性更改粘贴更改”上,函数E{ 变量数量=$'quantity'.val; }; 产品1 产品2 产品3 添加以下行。它将数量与价格相乘,并将其设置为输入的总和 $'product'.changefunction{ var price=parseInt$this.childrenoption:selected.attrdata-price; $price.attrvalue,price; $quantity.triggerinput;//此行将更新对产品更改的任何反映。 }; $“数量”。在“输入属性更改粘贴更改”上,函数E{ 变量数量=$'quantity'.val; 如果$quantity.val>0 { $sum.valparseint数量,10*parseInt$price.val,10; } }; 产品1 产品2 产品3Javascript 自动填写计算表,javascript,jquery,forms,input,Javascript,Jquery,Forms,Input,我有一个关于产品的例子,当选择一个选项时,输入价格自动填入数据价格,然后在输入数量中输入数量,最后在输入总和中输入价格*数量的结果。如何在更改输入和选择时求和 $'product'.changefunction{ var price=parseInt$this.childrenoption:selected.attrdata-price; $price.attrvalue,price; }; $“数量”。在“输入属性更改粘贴更改”上,函数E{ 变量数量=$'quantity'.val; };
添加一个额外的calculate total函数,并从两个事件处理程序调用它。无论何时更改,总数都将更新 $'product'.changefunction{ var price=parseInt$this.childrenoption:selected.dataprice; $price.valprice; 卡尔克托; }; $“数量”。在“输入属性更改粘贴更改”上,函数E{ 卡尔克托; }; 函数计算器{ var价格=$‘价格’.val | | 0; 变量数量=$'quantity'.val | | 0; var总计=价格*数量; $‘总和’。总值; } 产品1 产品2 产品3 要捕获数量的值,可以使用模糊方法。当用户从输入框中移除焦点时,将调用模糊函数并计算总和 此外,您还可以创建一个模块displaySum方法来获取价格和数量输入的值,并更新总和输入 $'product'.changefunction{ var price=parseInt$this.childrenoption:selected.attrdata-price; $price.attrvalue,price; 显示总和; }; $“数量”。在“模糊”上,函数E{ 显示总和; }; 函数显示和{ 让price=parseInt$'price'.val; 让数量=parseInt$'quantity'.val; ifisNaNprice{price=0;} IFISNAQUANTY{quantity=0;} 让总和=价格*数量; $sum.valsum } 产品1 产品2 产品3
if ($("#quantity").val() > 0)
{
$("#sum").val(parseInt(quantity, 10) * parseInt($("#price").val(),10) );
}