我正在尝试修改邮政信箱验证脚本以仅在选择“运送到此地址”时对其进行验证。该表单显然使用了非常简单的表单验证。表格部分是:
<input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_yes" value="1" <?php if ($this->isUseBillingAddressForShipping()) {?> checked="checked"<?php }?> title="<?php echo $this->__('Ship to this address') ?>" onclick="$('shipping:same_as_billing').checked = true;" class="radio" /><label for="billing:use_for_shipping_yes"><?php echo $this->__('Ship to this address') ?></label></li>
<li class="control">
<input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_no" value="0" <?php if (!$this->isUseBillingAddressForShipping()) {?> checked="checked"<?php }?> title="<?php echo $this->__('Ship to different address') ?>" onclick="$('shipping:same_as_billing').checked = false;" class="radio" /><label for="billing:use_for_shipping_no"><?php echo $this->__('Ship to different address') ?></label>
到目前为止,脚本是
Validation.add('validate-pobox', 'One or more items purchased cannot be shipped to a PO Box', function (v){
var pattern = /\b([P|p](OST|ost)?\.?\s?[O|o|0](ffice|FFICE)?\.?\s)?([B|b][O|o|0][X|x])\s(\d+)/;
if( document.getElementById("billing:use_for_shipping_yes").checked) // this isn't working
if (!pattern.test(v)) return true; else return false;
});
我对 jQuery 不是很熟悉(我正在慢慢学习!),但无论我尝试什么,无论选择哪个按钮,脚本仍然会验证地址字段。我也试过:
if( $("billing:use_for_shipping_yes").checked)
if( $("billing:use_for_shipping_yes").is("checked"))