Javascript innerHTML更改不起作用
我不喜欢带着看似简单的问题来到这里,但我被难住了,并且尝试了多种解决方案 我有一个复选框,因此当点击时,它们将运行一个函数,该函数将更改购物车的总价。然而,我甚至无法在文本框上获得一个简单的innerHTML更改,该文本框将显示onclick事件的总价 HTML/php:Javascript innerHTML更改不起作用,javascript,html,Javascript,Html,我不喜欢带着看似简单的问题来到这里,但我被难住了,并且尝试了多种解决方案 我有一个复选框,因此当点击时,它们将运行一个函数,该函数将更改购物车的总价。然而,我甚至无法在文本框上获得一个简单的innerHTML更改,该文本框将显示onclick事件的总价 HTML/php: <?php .... .... echo "<span class='chosen'><input type='checkbox' name='event[]' value='{$event['eve
<?php
....
....
echo "<span class='chosen'><input type='checkbox' name='event[]'
value='{$event['eventID']}' title='{$event['eventPrice']}'
onclick='price_calc(this.title, this)'/></span>"
?>
<div id="checkCost">
<h2>Total cost</h2>
Total <input type="text" name="total" id="total" size="10" readonly="readonly" />
</div>
....
....
<script src="bookingJS.js"></script>
</body>
感谢您提前提供的任何提示。“总计”是一个字段。因此,请尝试document.getElementById('total')。value
innerHTML用于span、div等非字段元素。要设置
输入[type=text]
值,请使用.value
而不是innerHTML
:
function price_calc(price, chkbx) {
document.getElementById('total').value = 'Hello';
alert(document.getElementById('total').value);
}
试试这个:
document.getElementById('total').value="Hello";
alert(document.getElementById('total').value);
document.getElementById('total').value="Hello";
alert(document.getElementById('total').value);