Javascript onclick按钮不能在wordpress中的移动设备上工作

时间:2017-08-27 17:41:02

标签: javascript jquery wordpress

JavaScript OnClick事件按钮无法在使用Jquery的移动设备上运行。

我研究了很多,并尝试了所有的建议,但仍然没有工作!!!

此功能在桌面版中完美运行!!!

这是一个wordpress网站。

这是我的代码:

    <div class="smt">
<div class="container-fluid">
    <div class="row">

        <div class="col-lg-12">
            <div class="row">
                <div class="left-column">
                    <input id="noc" class="form" type="text" placeholder="Enter Number of Components"  />
                    <input id="nos" class="form" type="text" placeholder="Enter Number of Suppliers"  />
                </div>
                <div class="btn-container">
                    <button class="btn" id="calculateBtn">Calculate Savings*</button>
                </div>
                 <div class="right-column">
                <h4><b>Hours Saved: <span id="ts" class="result"></span></b></h4>
                <h4><b>Amount Saved: <span id="as" class="result"></span></b></h4>
               </div >
            </div>
        <div class=""></div>
           </div>  
           </div>

    </div>
</div>
<script>

 $(window).load(function() { 
    $('#calculateBtn').on('click touchstart', function() {

    var noc = $("#noc").val();
    var nos = $("#nos").val();
    if (noc == "" && nos == "") {
      //  alert("Please Enter the values in the fields");
    } else {
        var crfq1 = 1;
        var crto1 = 3;
        var ana1 = 2;
        var cpo1 = 2;
        var tt = ((noc * nos) * (crfq1 + crto1 + ana1 + cpo1)) / 60;
        var crfq2 = 1;
        var crto2 = 0;
        var ana2 = 1;
        var cpo2 = 0.5;
        var tt2 = (((noc * nos) + 1) * (ana2 + cpo2)) / 60;
        var tts = tt - tt2;
        var totalAmountSaving = tts * 30;
        $("#ts").text(tts.toFixed(2));
        $("#as").text('$' + totalAmountSaving.toFixed(2));
        var noc = $("#noc").val("").focus();
        var nos = $("#nos").val("");
    }

    });
 });


</script>

谢谢

1 个答案:

答案 0 :(得分:0)

您可以尝试使用点击事件:https://www.w3schools.com/jquerymobile/event_tap.asp