-3 html javascript onclick innerhtml
我不知道为什么,但我的一个按钮的onclick事件无法正常工作.这是我用来在表单上进行计算的那个.我有两个正常运行的,一个触发打印功能,另一个重定向到另一个页面.
这是3个按钮的Javascript:
<script type="text/javascript">
function previewFunction() {
window.location.href = "preview.php";
}
function printFunction() {
window.print();
}
function calculateFunction() {
var e = document.getElementById("limit");
var limit = e.options[e.selectedIndex].value;
var rate = .0075;
var fee = .0025;
var cost = (rate + fee) * limit;
document.getElementById("cost").innerHtml = cost;
}
</script>
Run Code Online (Sandbox Code Playgroud)
calculateFunction()是不起作用的.
这是计算按钮/成本范围的HTML:
<tr>
<th align="center"><input class="buttonStuff" type="button" onclick="calculateFunction()" value="Calculate" /></th>
<th valign="bottom" align="center"><span style="font-size: 20pt;">Cost: </h3><span id="cost" style="text-decoration:underline;">$0.00</span></th>
</tr>
Run Code Online (Sandbox Code Playgroud)
这是两个有效的HTML:
<tr class="container">
<td width="25%" align="center"><input class="buttonStuff" type="button" onclick="previewFunction()" value="Preview" /></td>
<td width="25%" align="center"><input type="button" class="buttonStuff" onclick="printFunction()" value="Print" /></td>
</tr>
Run Code Online (Sandbox Code Playgroud)
单击"计算"时没有任何反应.我敢肯定这是一个简单的事情,我忽略了,也许不是.
感谢您的任何帮助,您可以提供.如果我需要发布更多代码,请告诉我.
Javascript区分大小写innerHTML,不是innerHtml
document.getElementById("cost").innerHTML = cost;
Run Code Online (Sandbox Code Playgroud)