Bootstrap Dual listbox and single select with fetching values in alert with add/delete/close option in jquery

主宰稳场 提交于 2019-12-01 12:45:39

问题


Can you please anyone help me how to solve this issue.

Bootstrap have dual listbox option with single/multiple select only.

I need dual listbox with single select.

Explanation:

For example:

I have dual listbox,left listbox have 5 options. I need single select.(i.e) If i select the single option in the left listbox, it shown popup(alert) with fetching the respective field values and also the popup have Add or Cancel button to add/cancel the values.After clicking the add option in popup it will be added in right list box.

And if i select the option in right listbox , again it shown popup(alert) with fetching the respective field values and also the popup have Delete or Cancel button to delete/cancel the values in the right listbox.

Please any one give solution to this problem,

Thanks,


回答1:


//Html
<select id="sel1">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
</select>
<select id="sel2"></select>
//This is the JS
//On change of the first select
$('#sel1').on('change', function (e) {
    e.preventDefault();
    var selVal = $(this).val();
    var selHtml = $(this).find('option:selected').text();
    moveItem('#sel1', '#sel2', selVal, selHtml);//call our function
});
//On change of the second select
$('#sel2').on('change', function (e) {
    e.preventDefault();
    var selVal = $(this).val();
    var selHtml = $(this).find('option:selected').text();
    moveItem('#sel2', '#sel1', selVal, selHtml);//call our function
});
//Move function take 4 parameters
function moveItem(moveFrom, moveTo, selVal, selHtml) {
    if (confirm("Are you sure? : " + selVal)) {//Confirm dialogue box comes up and on selecting 'ok' this part will be executed
        $(moveTo).append('<option value="' + selVal + '">' + selHtml + '</option>');//append a value to select
        var mId = moveFrom + ' option[value="' + selVal + '"]';
        $(mId).remove();//remove value from the other select
    }
    return false;
}


来源:https://stackoverflow.com/questions/25447664/bootstrap-dual-listbox-and-single-select-with-fetching-values-in-alert-with-add

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!