Home > Backend Development > PHP Tutorial > 数组解决,该如何处理

数组解决,该如何处理

WBOY
Release: 2016-06-13 12:49:27
Original
1001 people have browsed it

数组解决
单价:
数量:
总价:
<script><br /> function fx(){<br /> var s=document.getElementById('danjia[]').value;<br /> if(!s)return;<br /> s=parseInt(s);<br /> var c=document.getElementById('shuliang[]').value;<br /> c=parseInt(c);<br /> if(!c)return;<br /> document.getElementById('zongjia').innerHTML=Math.round(s*c)<br /> }<br /> </script>

我这个是数组,怎么让总价放到对应的总价td里


------解决方案--------------------
 var s=document.getElementById('danjia[]').value;
应为
 var s=document.getElementById('danjia').value;

 var c=document.getElementById('shuliang[]').value;
应为
 var c=document.getElementById('shuliang').value;
------解决方案--------------------
你用的是getElementById();括号里应该写的是属性id,而不是用的getElementsByName();
------解决方案--------------------
引用:
楼上两位帮我解决了问题,但是总计怎么计算?就是说所有的总价和值。求解,

楼主不怎么喜欢用jquery的
如果喜欢用的话可以这样写 var zj;
zj=$('#danjia').val()*$('#shuliang').val();
$('#zongjia').text(zj);
希望回答对你有帮助
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template