成功的wp_enqueue_script后,脚本在页面中不起作用

时间:2015-09-18 06:25:44

标签: javascript wordpress

当我将所有代码添加到页面代码中时,我设法让我的代码工作但在使用wp_enqueue_script()之后,即使在页面源中调用脚本,它也无法正常工作。

我是否必须以与“页面布局”不同的方式调用我的脚本?

在页面来源中显示:

<script type='text/javascript' src='http://www.huntingvalue.com/wp-content/themes/contango/lib/js/calcStake.js?ver=4.3.1'></script>

实际的脚本是

    <script type="text/javascript">
    function calcStake() {
        var BWodds = document.getElementById('BWodds').value;
        var div = document.getElementById('div').value;
        var stake = document.getElementById('stake').value;
        var EWodds = document.getElementById('EWodds').value;
        var EPodds = document.getElementById('EPodds').value;
        var commission = document.getElementById('commission').value;

        var BPodds = (((BWodds - 1) / div) + 1).toFixed(3);
        var ewstake = 2*stake;
        var WLstake = ((BWodds*stake)/(EWodds-(commission/100))).toFixed(2);
        var PLstake = ((BPodds*stake)/(EPodds-(commission/100))).toFixed(2);
        var ProfitW = ((BWodds*stake)-(WLstake*(EWodds-1)))-stake;
        var ProfitP = ((BPodds*stake)-(PLstake*(EPodds-1)))-stake;
        var ProfitT = ProfitW+ProfitP;

        document.getElementById('BPodds').value = BPodds;
        document.getElementById('ewstake').value = ewstake;
        document.getElementById('WLstake').value = WLstake;
        document.getElementById('PLstake').value = PLstake;
        document.getElementById('ProfitW').value = ProfitW.toFixed(2);
        document.getElementById('ProfitP').value = ProfitP.toFixed(2);
        document.getElementById('ProfitT').value = ProfitT.toFixed(2); }</script> 

,页面布局为

<table class="table" border="0" width="500" cellspacing="1" cellpadding="3">
<tbody>
<tr class="calcheading">
<td colspan="3"><strong>Each Way Lay Calculator</strong></td>
</tr>
<tr class="calchead">
<td align="center">Bookmaker Win odds:</td>
<td align="center">Place divider:</td>
<td align="center">Bookmaker Place odds:</td>
</tr>
<tr class="calcrow">
<td align="center">
<input id="BWodds" type="text" value="10" onclick="calcStake()" />
</td>
<td align="center">
<input id="div" type="text" value="4" onclick="calcStake()" />
</td>
<td align="center">
<input id="BPodds" />
</td>
</tr>
<tr class="calchead">
<td align="center">Stake:</td>
<td align="center">Total EW stake:</td>
</tr>
<tr class="calcrow">
<td align="center"><input id="stake" type="text" value="10" onclick="calcStake()"/></td>
<td align="center"><input id="ewstake"/></td>
</tr>
<tr class="calchead">
<td align="center">Exchange Win odds:</td>
<td align="center">Exchange Place odds:</td>
<td align="center">Commission:</td>
</tr>
<tr class="calcrow">
<td align="center"><input id="EWodds" type="text" value="10" onclick="calcStake()"/></td>
<td align="center"><input id="EPodds" type="text" value="3" onclick="calcStake()"/></td>
<td align="center"><input id="commission" type="text" value="5" onclick="calcStake()"/></td>
</tr>
</table>
<tr><button onclick="calcStake()">Calculate</button></tr>
<table class="table" border="0" width="500" cellspacing="1" cellpadding="3">
<tr class="calchead">
<td align="center">Win Lay stake:</td>
<td align="center">Place Lay stake:</td>
</tr>
<tr class="calcrow">
<td align="center"><input id="WLstake"/></td>
<td align="center"><input id="PLstake"/></td>
</tr>
<tr class="calchead">
<td align="center">Profit from Win market:</td>
<td align="center">Profit from Place market:</td>
<td align="center">Total profit:</td>
</tr>
<tr class="calcrow">
<td align="center"><input id="ProfitW"/></td>
<td align="center"><input id="ProfitP"/></td>
<td align="center"><input id="ProfitT"/></td>
</tr>
</tbody>
</table>

0 个答案:

没有答案