我有一个函数可以计算用户选择的票数(从下拉列表中)并将其乘以票证价格(该票证价格存储在我的sql数据库)。从Javascript函数获取值以显示在其他地方
函数本身工作正常:
function quantityChange(selElem) {
//Select the value of the drop down list
var quantity = $('#showQuantity option:selected').val();
//get the value of the number from the tPrice column in 'ticket' table
var ticket = parseInt(document.getElementById('ticketPriceHidden').value);
//get the venue value
var venue = document.getElementById('venuePlaceHidden').value;
//multiply them together
var total = quantity * ticket;
document.getElementById('summary').innerHTML= 'You have chosen'+ ' ' + quantity + ' ' + 'tickets @' + ' ' + venue + ' = ' + ' ' + ' £' + total;
}
调用此函数在一个名为“票” DIV,一旦用户从这个功能看到计算总,然后他们按了“继续”按钮,隐藏这个div,并显示一个新的div称为“交付”,所以结果不会被丢弃。
我想要做的是这样的:我想再次获得函数quantityChange(selElem)的结果,但是在一个全新的div中称为'summary'。有没有办法做到这一点?
任何帮助非常感谢,谢谢。
将函数写成更具抽象性的函数而不是返回值。使用该值调用另一个函数将其设置为“摘要”。完成。 – Smamatti 2012-03-14 16:25:22
这是jQuery和纯DOM方法的有趣组合。你在用什么“selElem”?而不是将元素ID硬编码到函数中,请将其作为参数。或者对计算值更灵活,返回结果。 – 2012-03-14 16:26:08
谢谢你的快速回复。 @Felix King,对于传递参数的语法以及我应该返回的内容,我仍然有点小白。请你能够如此善意地离开我需要编写的代码以使这个功能更加灵活吗? – 2012-03-14 16:33:44