简体   繁体   中英

double click function in jquery for select option element

I have created two selectBoxes ,I am passing data from one box to another through buttons using jquery. On click of the button ,the data passes.I want the same functionality to work when i double click that select option element as well,but its not working.

$(document).ready(function () {
        $("#ShiftRight,#ShiftLeft").click(function (event) {

                var ID = $(event.target).attr("ID");
                var ChooseFrom = ID == "ShiftRight" ? "#ChooseLeft" : "#ChooseRight";
                var moveTo = ID == "ShiftRight" ? "#ChooseRight" : "#ChooseLeft";

                var SelectData = $(ChooseFrom + " :selected").toArray();
                $(moveTo).append(SelectData);
                SelectData.remove;
            });
        });

You can use the jquery on( "click dblclick", handler ) . The dblclick event is sent to an element when the element is double-clicked.

$("#ShiftRight,#ShiftLeft").on("dblclick click", function() { 

    var ID = $(event.target).attr("ID");
    var ChooseFrom = ID == "ShiftRight" ? "#ChooseLeft" : "#ChooseRight";
    var moveTo = ID == "ShiftRight" ? "#ChooseRight" : "#ChooseLeft";

    var SelectData = $(ChooseFrom + " :selected").toArray();
    $(moveTo).append(SelectData);
    SelectData.remove;
});

You can use dblclick for double click event.

 $(document).ready(function () {
    $("#ShiftRight,#ShiftLeft").dblclick(function (event) {

            var ID = $(event.target).attr("ID");
            var ChooseFrom = ID == "ShiftRight" ? "#ChooseLeft" : "#ChooseRight";
            var moveTo = ID == "ShiftRight" ? "#ChooseRight" : "#ChooseLeft";

            var SelectData = $(ChooseFrom + " :selected").toArray();
            $(moveTo).append(SelectData);
            SelectData.remove;
        });
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM