嗨,我正试图将我的movieprice数组从复选框值传递给另一个计算选择总数的函数,但我的代码没有;t运行
Hi am trying to pass my movieprices array from checkbox values to another function that calculates the total of the selections but my code doesn't run
Am试图在这里定义某个函数来计算总数var总计=0;var movie_prices=[];//创建电影价格数组,但它正在等待用户选择的值,如14、16、35//函数calculateTotal(arguments){//这是被调用的函数//
var len = arguments.length
for(vari=0; i<len;i++){
total+= parseInt(arguments[i]); return total;
}
}
This function will display the total by determining which movies are checked;
function displayTotal(){
var obj = document.getElementById('flicks'); //flicks is an id to the table element containing checkboxes//
var top = obj.getElementByTagName('input');// reference to checkboxes of input type//
var leng = top.length;
for(vari=0; i< leng;i++){
if(top[i].checked ){
movie_prices.push(top[i].value;);
}
}
call to the calculateTotal function with movieprices array as an argument;
calculateTotal(movie_prices);
window.alert("The total amount you now owe is:" + total); // display total//
}
到目前为止,我看到了两件事。第七行应该是一个注释,所以如果你在运行时没有注释掉它,那就会给你带来错误。
此外,方法top[i].value似乎未定义。您在代码中的何处声明了值?
相关文章:
- 为什么不是'我的函数在解析云代码中工作吗?当我在Angular和Express中测试时,它是有效的
- 使用JAVASCRIPT转换货币.可以't通过我的函数设置转换后的输入文本字段的值
- 为什么我的函数没有被调用呢
- 为什么我的函数没有返回准确的计数
- 我的函数返回“未定义”
- 用我的函数jquery给出数据/参数
- 从未达到我的函数调用-ReactJs 0.12.0
- 我的函数不会返回要保存在数组中的对象
- 为什么点击或更改事件都没有触发我的函数
- 为什么如果我的函数中的范围被 javascript 解释器完全忽略了
- 我的函数调用在回显中不起作用
- 我的函数返回空.为什么
- 我的函数不起作用,Ajax调用,JQuery,调用外部?我不知道
- 如何在我的函数中使用 .bind()
- 在jQuery中,我的函数不起作用
- 为什么不是'我的函数未按预期在文档加载时运行
- 传递的变量不适用于我的函数-Javascript
- jQuery:我的函数需要一个反垃圾邮件
- 为什么不是't调用我的函数
- 为什么我的函数参数说是未定义的