我觉得这个最好的解决办法是要求帐单地址,然后有一个简单的复选框,说“船到帐单地址” - 默认选中 - 当有人取消选中该复选框,在“运输“字段出现。服务器端仍然应该处理从billing-> shipping字段复制该信息,并非所有用户都使用javascript。
至于jQuery的方式从一组字段复制到另一个你可以尝试沿着线的东西:
// just so we are only working within the one form we want to work with:
var $form = $('#ourform');
// all fields whos names begin with 'billing':
$('input[name^=billing]', $form).each(function() {
var $field = $(this);
// replace the billing with shipping
var newName = $field.attr('name').replace(/^billing/, 'shipping');
// look for an input named shipping instead of billing,
// and set its value to our value.
$('input[name='+newName+']', $form).val($field.val());
});
如果您使用的是您输入名字[和]字符 - 你将需要用这行代码逃避它们:
newName = newName.replace(/\[/, '\\[').replace(/\]/, '\\]');
甜圣球。我可以吻你。这太神奇了,谢谢! – Jason 2009-08-03 21:41:30