简体   繁体   English

如何保存jquery动态生成的数据

[英]How to save jquery dynamic generated data

I am using a math formula on my site to help users determine how many calories they must consume per day to lose weight, maintain current weight or build muscle. 我在我的网站上使用数学公式来帮助用户确定他们每天必须消耗多少卡路里来减肥,保持当前体重或增加肌肉。 After they enter their personal stats they click click the "Generate Calorie Wallet" button and Jquery does the math and dynamically enters the data into three(3) empty cells each with separate class names depending on which of the 3 results they're looking fore. 在他们输入他们的个人统计数据后,他们点击“生成卡路里钱包”按钮,Jquery进行数学运算并动态地将数据输入三(3)个空单元格,每个单元格具有单独的类名,具体取决于他们所看到的3个结果中的哪一个。 Here is the table below. 这是下表。

 <table>
    <tr>
        <td>Your Weight Loss Calorie Wallet</td>
        <td class="row_1"></td>
    </tr>
    <tr>
        <td>Your Maintanance Calorie Wallet</td>
        <td class="row_2"></td>
    </tr>
    <tr>
        <td>Your Muscle Gain Calorie Wallet</td>
        <td class="row_3"></td>
    </tr>
</table>
<form>
    <input type="button" class="save_wallet" value="Save To Profile"/>
</form>

The classes row_1, row_2, and row_3 are where the results are dynamically appearing from jquery and as you can see, there is a button below the table which will be used to let the user save the data into their profile in which I will use a simple HTTP Post request to carry out. 类row_1,row_2和row_3是结果从jquery动态显示的位置,正如您所看到的,表下方有一个按钮,用于让用户将数据保存到他们将在其中使用的数据库中。简单的HTTP Post请求执行。 The problem is when I run tests using alerts boxes I can't get jquery to pick up the dynamically generated data. 问题是当我使用警报框运行测试时,我无法获取jquery来获取动态生成的数据。 I keep getting empty alert boxes. 我一直在拿空警报箱。

Here is the code currently being used in jquery to calculate calorie wallet and insert into the rows and also the code used for the button to generate an alert. 这是当前在jquery中用于计算卡路里钱包并插入行的代码,以及用于生成警报的按钮的代码。

 //Used for calculating the calorie wallet based on Katch Mcardle.
    $('.km_calculate').on("click",function(){
        var lbm = $(this).parent().children('.lbm').val();
        var activity = $(this).parent().children('.activity').val();
        var wt_unit = $(this).parent().children('.wt_unit').val();
        var bmr = 370 + (21.6 * lbm / wt_unit);
        var calorie_wallet = activity * bmr;
        var fatloss_wallet = calorie_wallet * .8;
        var muscle_gain = calorie_wallet * 1.2;
        $('.formula_2').slideUp();
        $('div#calorie_wallet').slideDown();
        $('.row_1').text(Math.round(fatloss_wallet));
        $('.row_2').text(Math.round(calorie_wallet));
        $('.row_3').text(Math.round(muscle_gain));
    });
    //Used to save the results from the math formulas
    $('.save_wallet').click(function(){
        var fatloss = $('.row_3').val();
            alert(fatloss);                              
    });

I hope some one can please help me with this, I have tried many attempts on my own by going to jquery.com but it's too much information to sift through and taking me too long to figure out on my own. 我希望有人可以帮助我这个,我已经尝试了很多尝试,只是去了jquery.com,但是有太多的信息需要筛选并花费我太长时间才能找到我自己。 Thank you all very much. 非常感谢你们。

尝试使用.text().html()而不是.val() ,这是输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM