0
我使用下面的代碼來嘗試複製信息從一組地址字段到另一組時複選框被選中。除了狀態選擇框(下拉框)之外,它全部工作。這讓我瘋狂。jQuery - 爲什麼不選擇框信息重複,但其餘部分將
//on page load
$(document).ready(function() {
//when the checkbox is checked or unchecked
$('#copyaddress').click(function() {
// If checked
if ($(this).is(":checked")) {
//for each input field
$('#cc input', ':visible', document.body).each(function(i) {
//copy the values from the billing_fields inputs
//to the equiv inputs on the shipping_fields
$(this).val($('#info input').eq(i).val());
});
//won't work on drop downs, so get those values
var c_state = $("select#c_state").val();
// special for the select
$('select#cc_state option[value=' + c_state + ']').attr('selected', 'selected');
} else {
//for each input field
$('#cc input', ':visible', document.body).each(function(i) {
// put default values back
$(this).val($(this)[0].defaultValue);
});
// special for the select
$('select#cc_state option[value=""]').attr('selected', 'selected');
}
});
});
感謝那些真正變薄下來。現在正在工作。 – Vincent 2011-04-18 21:02:35