更改表单提交的值?

时间:2013-04-10 13:54:33

标签: php jquery html forms

我在表单中有一个包含两组不同字段的表单,一个是帐单邮寄地址,另一个是送货地址。

我已经编写了一些jQuery,以便您可以隐藏运送表单,并在结算表单中填写详细信息(如果您要运送到同一地址)。

这是我的jQuery:

$('#reveal-shipping').click(function(){
    if( $('.wpsc_checkout_table.table-2').css('display') == 'none' ){

        $('.wpsc_checkout_table.table-2').slideToggle();
        $('.wpsc_checkout_table.table-2').find('input, select, textarea').val('');
        document.getElementById('reveal-shipping').innerHTML = 'Ship to my billing address ←';

    } else {

        //fields is an array containing an array of two selector strings, one for the billing form and one for the shipping.
        for ( i=0; i < fields.length; i++ ){
            thisval = $(fields[i][0]).val();
            $(fields[i][1]).val( thisval );
        }
        $('.wpsc_checkout_table.table-2').slideToggle();
        document.getElementById('reveal-shipping').innerHTML = 'Ship to a different address &rarr;';

    }
});

我想知道我是否可以运行for循环,这是用值填充隐藏的输入元素的部分,onClick提交按钮,或者这些值是否已经提交。

如果没有,什么时候运行它以确保正确提交值?也许onunfocus? (请告诉我这个的实际名称)

提前致谢

1 个答案:

答案 0 :(得分:1)

您可以在提交按钮的onClick事件中执行此操作,也可以在表单上注册submit事件。您的事件在提交的其余部分之前运行。这就是您可以在表单上调用验证方法并通过返回值false来中断提交的原因。

您正在考虑的'onunfocus'事件是blur

相关问题