Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery-为什么不选择框信息复制,但其余的将选择_Jquery - Fatal编程技术网

jQuery-为什么不选择框信息复制,但其余的将选择

jQuery-为什么不选择框信息复制,但其余的将选择,jquery,Jquery,我正在使用下面的代码尝试在选中复选框时将信息从一组地址字段复制到另一组。除“状态选择框”下拉框外,其他所有功能均有效。这快把我逼疯了 //on page load $(document).ready(function() { //when the checkbox is checked or unchecked $('#copyaddress').click(function() { // If checked if ($(this).is(":checked")) {

我正在使用下面的代码尝试在选中复选框时将信息从一组地址字段复制到另一组。除“状态选择框”下拉框外,其他所有功能均有效。这快把我逼疯了

 //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');
         }
     });
 });

设置单个值选择元素的值时,只需传递要选择的选项的文本值

这可以修改

    //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');
对此

$('select#cc_state').val($("select#c_state").val());