怎么让tp的值显示在当前的x[i]的div内?我这么写哪里错了?
for(i=0;i<x.length;i++){document.write("<divclass='danyuan'>");document.write("<divcl...
for (i=0;i<x.length;i++)
{
document.write("<div class='danyuan'>");
document.write("<div class='tu'><img src='");
document.write(x[i].getElementsByTagName("lianjie")[0].childNodes[0].nodeValue);
document.write("'/></div><div class='price'>¥<span id='danjia'>");
document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
document.write("</span></div><div class='slsy'>剩余:");
document.write(x[i].getElementsByTagName("shuliang")[0].childNodes[0].nodeValue);
document.write("</div><div class='name_tu'>");
document.write(x[i].getElementsByTagName("name_tu")[0].childNodes[0].nodeValue);
document.write("</div><div class='gmsl'>购买数量:<input id='proNumber' value='2' onKeyUp='TotalPrice(this.value)' /></div>");
document.write("<div class='zjiage' id='zjiage'><strong>总价格:</strong>¥<span id='totalPrice'>")
document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
document.write("</span></div>");
document.write("</div>");
function TotalPrice(num){
var price= document.getElementById("danjia").innerHTML;
var tp= price * num;
document.x[i].getElementById("zjiage").getElementById("totalPrice").innerHTML = tp;
}
} 展开
{
document.write("<div class='danyuan'>");
document.write("<div class='tu'><img src='");
document.write(x[i].getElementsByTagName("lianjie")[0].childNodes[0].nodeValue);
document.write("'/></div><div class='price'>¥<span id='danjia'>");
document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
document.write("</span></div><div class='slsy'>剩余:");
document.write(x[i].getElementsByTagName("shuliang")[0].childNodes[0].nodeValue);
document.write("</div><div class='name_tu'>");
document.write(x[i].getElementsByTagName("name_tu")[0].childNodes[0].nodeValue);
document.write("</div><div class='gmsl'>购买数量:<input id='proNumber' value='2' onKeyUp='TotalPrice(this.value)' /></div>");
document.write("<div class='zjiage' id='zjiage'><strong>总价格:</strong>¥<span id='totalPrice'>")
document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
document.write("</span></div>");
document.write("</div>");
function TotalPrice(num){
var price= document.getElementById("danjia").innerHTML;
var tp= price * num;
document.x[i].getElementById("zjiage").getElementById("totalPrice").innerHTML = tp;
}
} 展开
1个回答
2014-11-11 · 知道合伙人软件行家
yfcp
知道合伙人软件行家
向TA提问 私信TA
知道合伙人软件行家
采纳数:1748
获赞数:5545
有多年网站建设相关工作经验。熟悉ASP、ASP.net、VB、JavaScript、HTML等语言和CSS、Ajax等相关技术。
向TA提问 私信TA
关注
展开全部
以下代码测试通过:
根据i的值定义不同的id,比如id=danjia0,id=danjia1。这样id就不会重复了。
<script>
for (i=0;i<x.length;i++)
{
document.write("<div class='danyuan'>");
document.write("<div class='tu'><img src='");
document.write(x[i].getElementsByTagName("lianjie")[0].childNodes[0].nodeValue);
document.write("'/></div><div class='price'>¥<span id='danjia"+i+"'>");
document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
document.write("</span></div><div class='slsy'>剩余:");
document.write(x[i].getElementsByTagName("shuliang")[0].childNodes[0].nodeValue);
document.write("</div><div class='name_tu'>");
document.write(x[i].getElementsByTagName("name_tu")[0].childNodes[0].nodeValue);
document.write("</div><div class='gmsl'>购买数量:<input id='proNumber"+i+")' value='2' onKeyUp='TotalPrice(this.value,"+i+")' /></div>");
document.write("<div class='zjiage' id='zjiage"+i+"'><strong>总价格:</strong>¥<span id='totalPrice"+i+"'>")
document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
document.write("</span></div>");
document.write("</div>");
}
function TotalPrice(num,n){
var price= document.getElementById("danjia"+n).innerHTML;
var tp= price * num;
document.getElementById("totalPrice"+n).innerHTML = tp;
}
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询