数学函数不起作用

math function wont work

本文关键字:不起作用 函数      更新时间:2023-09-26

我有一个名为"textmoney"的文本输入。在我的jQuery中,我有一个名为"dailyE"的变量。这个var基本上是"textmoney"。val/365。这将显示每天的估计产量。我无法工作的是我的"统计数据",它基本上显示了在"textmoney"中输入的数字的统计数据。我无法让它在statFunction中显示一个简单的数学函数。我已经试着解决这个问题有一段时间了。

这是我的jQuery:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script>
    $(document).ready(function() {

    var $demo = $('#demo');
    var $textMoney = $('#textmoney');
    var $moneydiv = $('#moneydiv');
    var $stat = $('#stat');
    var dailyE = $textMoney.val() / 365;
    var $second = (dailyE / 24) / 60 / 60 / 60;
    var $minute = (dailyE / 24) / 60 / 60;
    var $hour = (dailyE / 24);
    var $day = dailyE;
    var $week = dailyE * 7;
    var $month = (dailyE * 7) * 30;
    var $year = (dailyE * 7) *30 *12;
    var $secondp = $('#second');
    var $minutep = $('#minute');
    var $hourp = $('#hour');
    var $dayp = $('#day');
    var $weekp = $('#week');
    var $monthp = $('#month');
    var $yearp = ('#year');
    $('#stat').hide();
    function getmoney(){
        var money = $textMoney.val();
            if (isNaN(money) || money === '') {
                $demo.text('You aint enter no $$$$$$');
            } else {
                var dailyE = $textMoney.val() / 365;
                $demo.text('$' + dailyE + ' per day');
            }
    }
    function statFunction() {
        $stat.show();
        $secondp.text("$second");
    }
    // on enter key
    $textMoney.keydown(function(e) {
        if (e.which === 13) {
            getmoney();
            $('#stat').show();
        } else if ($(this).val() === '') {
            $demo.text('');
            $('#stat').hide();
        }
    }).mouseover(function() {
        $(this).css('border', '1px solid black');
    }).mouseout(function() {
        $(this).css('border', '1px solid grey');
    });
    // on click 
    $moneydiv.click(function(){    
        getmoney();
        $('#stat').show();
     });
     $stat.click(function() {
        statFunction();
     })
});
</script>

var $yearp = ('#year'); 缺少$

请将其更正为

var $yearp = $('#year');