我有一个INPUT文本字段,一个DIV和一个IMG。输入值和div的innerHTML用Javascript更改,但不会在显示中更改
在IMG具有onClick事件:
读取输入字段的当前值,
1增加它,
做了计算与增加的值,
将结果写入DIV。
输入的值总是增加的正确方法和DIV的innerHTML始终得到正确的结果,但没有在显示变化。即使在“背景”中正确完成所有操作,显示的数字也始终保持不变。
其中有趣的事我在同一网站的另一个地方使用了相同的操作,那里的一切工作和完美显示。
下面是函数:
function priceCalculator(max_amound,price,id)
{
var amound = parseInt(document.getElementById('sell_amound_' + id).value);
max_amound = parseInt(max_amound);
if (amound < max_amound)
{
amound = amound + 1;
document.getElementById('sell_amound_' + id).value = amound;
var item_value = amound * price;
document.getElementById('price_' + id).innerHTML = item_value;
alert(document.getElementById('sell_amound_' + id).value + ',' + document.getElementById('price_' + id).innerHTML);
}
}
这里是PHP代码中的元素:
<img src="images/plus.png" onclick="priceCalculator(\''.$bag_items[$i]['amound'].'\',\''.$bag_items[$i]['infos']['price'].'\',\''.$i.'\')" />
<form>
<input id="sell_amound_'.$i.'" type="text" readonly value="1" />
</form>
<div id="price_'.$i.'">'.$bag_items[$i]['infos']['price'].'</div>
在函数结束时的警报显示正确的价值观,但显示的值留一样。
这是一个非常简单的操作...可能是什么问题?
编辑:
加载“项”看起来像这样的源代码(这部分从数据库循环创建的,当然,我删除从代码和那些不相干的造型后许多的div是因为他们的存在):
<td>
<img id="item_pic_3" src="images/potions/3.png" onClick="shopSellInfo('3')" />
<div>26</div>
<form>
<input type="hidden" id="selected_item" value="" />
</form>
<div id="item_3" style="display: none;">
<span>blah...</span><br />
<span>
<br />blah...<br /><br />
<div>
<div>
<img src="images/increase.png" onclick="priceCalculator('26','10','3')" /><br />
</div>
<div>
<form>
<input id="sell_amound_3" type="text" readonly value="1" />
</form>
/26
</div>
</div>
<br />
<div id="price_3">10</div>
</span>
</div>
</td>
shopSellInfo(“3”)是使ITEM_3显示在正确的地方的功能。
向我们展示呈现的HTML而不是PHP代码。 – glortho 2012-02-22 02:16:29