Wordpress jquery不起作用(计算系统)

Wordpress jquery wont work (Calculation System)

本文关键字:计算系统 不起作用 jquery Wordpress      更新时间:2023-09-26

嗨,我无法让jquery脚本工作,也找不到原因。如果有人能帮我解决这个问题,那就太棒了。我试过插件和其他东西,但它就是不起作用。

<!doctype html>
<html>
<script type="text/javascript" src="files/jquery-1.8.1.js"></script>
<meta charset="utf-8" />
<title> Checkbox Summation </title>
<style type="text/css">
 .cbValue { }
</style>
<body>
<div id="CostBox">
<input type="checkbox" class="cbValue" value="9.99"  onclick="UpdateCost()">Product 1 ( 9.99)<br>
<input type="checkbox" class="cbValue" value="19.99" onclick="UpdateCost()">Product 2 (19.99)<br>
<input type="checkbox" class="cbValue" value="27.50" onclick="UpdateCost()">Product 3 (27.50)<br>
<input type="checkbox" class="cbValue" value="45.65" onclick="UpdateCost()">Product 4 (45.65)<br>
<input type="checkbox" class="cbValue" value="87.20" onclick="UpdateCost()">Product 5 (87.20)<br>
<input type="text" id="totalcost" value="" size="6"> Total ($)
</div>
<script type="text/javascript">
function UpdateCost() {
  var sum = 0;
  var sel = document.getElementById('CostBox').getElementsByClassName('cbValue');
  for (i=0; i<sel.length; i++) {
    if (sel[i].checked) { sum += Number(sel[i].value); }
  }
  document.getElementById('totalcost').value = sum.toFixed(2);
} 

</script>
</body>
</html>

您的页面上没有任何jQuery代码
你有什么错误吗?jQuery源是否存在于文件/jQuery-1.8.1.js中?

您可以尝试从CDN加载jQuery以确定:

<script src="http://code.jquery.com/jquery-1.9.1.js">

另外,试着添加一些简单的东西,比如:

$(document).ready(function(){
  alert("jQuery Running");
});