如何从页面获取值以便jQuery可以处理它?

时间:2010-09-28 20:07:29

标签: jquery-validate

在我们的公用事业账单上,一个人只能玩他们欠(或更少)的金额到最高金额。我已经创建了一个方法来检查这个,但是,我需要能够传递他们所欠的总数来完成比较。我如何输出应付的总金额,以便jQuery可以收集该金额?

这是我的方法:

$.validator.addMethod('MaxDue', function(value, element, params) {
    var maxPay = parseFloat($(params.totalDue).val());
    var maxTotal = 750.00;
    var payAmount = parseFloat($(params.payment).val());
    return (payAmount <= maxPay || (maxPay > maxTotal && payAmount <= maxTotal));
}, 'Amount greater than dollar amount allowed.');

以下是相关验证规则的部分:

        "Payment.PayAmount": {
            required: true,
            min: 0.01,
            MaxDue: {
                totalDue: 88.84,
                payment: "#Payment_PayAmount"
            }
        }

以下是我的代码中受影响的输出区域:

<fieldset>

    <legend>Account Information</legend>
    <p>Current Balance: 88.84</p>
    <p>Amount to Pay: <input id="Payment_PayAmount" name="Payment.PayAmount" type="text" value="88.84" /></p>
</fieldset>

1 个答案:

答案 0 :(得分:0)

知道了。

// Validate the expiration date
$.validator.addMethod('MaxDue', function(value, element, params) {
    var maxPay = parseFloat(params.totalDue);
    var maxTotal = 750.00;
    var payAmount = parseFloat($(params.payment).val());
    return (payAmount <= maxPay || (maxPay > maxTotal && payAmount <= maxTotal));
}, 'Amount greater than dollar amount allowed.');

jQuery.Validate

        "Payment.PayAmount": {
            required: true,
            min: 0.01,
            MaxDue: {
                totalDue: $("#payment").text(),
                payment: "#Payment_PayAmount"
            }
        }

价值包含在<span>代码中。

    <p>Current Balance: <span id="payment">88.84</span></p>