1

我有这个

<input class="check-agree" type="checkbox" name="policy_agreement" id="fmCheck2" onclick="toggleAgreeButton();"/>
<input class="hidden-input" type="hidden" value="<?php echo Varien_Date::now(); ?>" name="policy_agreement_date"/>

和 jQuery

function toggleAgreeButton() {
        jQuery('.button.register').hide();

        var isAgree = jQuery('#fmCheck2').attr('checked');
        if (isAgree) {
            jQuery('#registerBtn').show();
            jQuery('.hidden-input').add;
        } else {
            jQuery('#disabled').show();
        }
    }

我想在检查后将日期和时间添加到值隐藏输入,我该怎么办?谢谢

4

1 回答 1

1

jsFiddle 演示

var months = new Array(12);
months[0] = "Jan";
months[1] = "Feb";
months[2] = "Mar";
months[3] = "Apr";
months[4] = "May";
months[5] = "Jun";
months[6] = "Jul";
months[7] = "Aug";
months[8] = "Sep";
months[9] = "Oct";
months[10] = "Nov";
months[11] = "Dec";

var d = new Date;
var amOrPm = d.getHours() >= 12 ? "PM" : "AM";

var x = months[d.getMonth("mmm")] + " " + d.getDate() + ", " + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + " " + amOrPm;
jQuery('.hidden-input').val(x);

编辑 - 我也添加了 hh:mm:ss AM/PM。

于 2013-10-02T13:54:43.470 回答