我想将送货地址复制到帐单邮寄地址, 但问题是当我选择印度作为国家和州作为古吉拉特邦然后在计费状态下显示第一个州。
这是我的代码:
送货国家:
<select class="form-control shippingCountry valid" id="shipping_country" name="shipping_country" aria-invalid="false">
<option value="1">Afghanistan</option>
<option value="2">Albania</option>
<option value="3">Algeria</option>
<option value="4">American Samoa</option>
<option value="5">Andorra</option>
<option value="6">Angola</option>
送货状态:
<select class="form-control shippingState" id="shipping_state" name="shipping_state">
<option value="1">Andaman and Nicobar Islands</option>
<option value="2">Andhra Pradesh</option>
<option value="3">Arunachal Pradesh</option>
<option value="4">Assam</option>
<option value="5">Bihar</option>
<option value="6">Chandigarh</option>
结算国家/地区:
<select class="form-control billingCountry" id="billing_country" name="billing_country">
<option value="1">Afghanistan</option>
<option value="2">Albania</option>
<option value="3">Algeria</option>
<option value="4">American Samoa</option>
<option value="5">Andorra</option>
<option value="6">Angola</option>
结算状态:
<select class="form-control billingCountry" id="billing_state" name="billing_state">
<option value="1">Andaman and Nicobar Islands</option>
<option value="2">Andhra Pradesh</option>
<option value="3">Arunachal Pradesh</option>
<option value="4">Assam</option>
<option value="5">Bihar</option>
<option value="6">Chandigarh</option>
JQuery:
$("#copyAdrs").change(function ()
{
if ($(this).prop("checked"))
{
$('#billing_street').val($('#shipping_street').val());
$('#billing_city').val($('#shipping_city').val());
$("#billing_country").val($('#shipping_country').val()).change();
$("#billing_state").val($('#shipping_state').val()).change();
}
});
答案 0 :(得分:0)
试试这个。
更有意义。
$("#copyAdrs").on("click",function () {
var cpy = this.checked;
$.each(["street","city","country","state"],function(_,item) {
$('#billing_'+item).val(cpy?$('#shipping_'+item).val():"");
});
});