Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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
Javascript 如何删除SELECT2中的选定值_Javascript_Jquery_Ajax_Jquery Select2 - Fatal编程技术网

Javascript 如何删除SELECT2中的选定值

Javascript 如何删除SELECT2中的选定值,javascript,jquery,ajax,jquery-select2,Javascript,Jquery,Ajax,Jquery Select2,大家好!我的select2 jquery有问题。我正在使用ajax附加选项的值。select2将显示在模式中。所以问题是,我想删除选定的值。我该怎么做?我在stackoverflow中尝试了许多解决方案,但找不到答案。这是我的密码: 在HTML中 <a data-toggle="modal" data-target="#customer-ba"> <i class="fa fa-users"></i> <span>Manage Cu

大家好!我的select2 jquery有问题。我正在使用ajax附加选项的值。select2将显示在模式中。所以问题是,我想删除选定的值。我该怎么做?我在stackoverflow中尝试了许多解决方案,但找不到答案。这是我的密码:

在HTML中

<a data-toggle="modal" data-target="#customer-ba">
    <i class="fa fa-users"></i>
    <span>Manage Customer</span>
</a>
<div class="modal fade" id="customer-ba" role="dialog">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title"><i class="fa fa-object-group"></i> Customer Section</h4>
        </div>
        <form role="form" class="" method="post" action="<?php echo base_url('customer/view_customer'); ?>">
            <div class="modal-body">                    
                <div class="row">
                    <div class="form-group">
                        <label>Type of service: </label>
                        <select class="default-select2 form-control c_delivery_types" id="c_delivery_types" name="service">
                            <option></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                <input type="Submit" class="btn btn-primary pull-right"></button>
            </div>
        </form>
    </div>
</div>

试试这个

$(".c_delivery_types").html(values);
在此代码之后:

$('.c_delivery_types').append('<option selected></option>').select2({
    placeholder: "Select delivery types",
    allowClear: true
});
$('.c_delivery_types')。附加('')。选择2({
占位符:“选择交付类型”,
allowClear:对
});
试试这个

$(".c_delivery_types").html(values);
在此代码之后:

$('.c_delivery_types').append('<option selected></option>').select2({
    placeholder: "Select delivery types",
    allowClear: true
});
$('.c_delivery_types')。附加('')。选择2({
占位符:“选择交付类型”,
allowClear:对
});

$(“.c_delivery_types”).select2().select2(“val”,“-1”);哦,不,它也不起作用了>$(“.c_delivery_types”).select2().select2(“val”,“-1”);哦,不,它也不起作用了>。哦,天哪,谢谢你,我尝试了你的代码,我做了一些修改,这是有效的代码$(“.c_delivery_types”).html(值);$('.c_delivery_types').append('').select2({占位符:“选择传递类型”,allowClear:true});哦,上帝,谢谢你,我尝试了你的代码,我做了一点修改,这是有效的代码$(“.c_delivery_types”).html(值);$('.c_delivery_types').append('').select2({占位符:“选择传递类型”,allowClear:true});