jQuery how to undo a select change

前端 未结 7 901
春和景丽
春和景丽 2020-12-02 14:13

I have a select box, and I\'d like to add a confirm before changing it to a specific option. Example:



          

          

    
$("input[name='test1']").change(function() { var response = confirm("do you want to perform selection change"); if (response) { var container = $(this).closest("div.selection"); //console.log(container); //console.log("old sel =>" + $(container).find(".selected").val()); $(container).find(".selected").removeClass("selected"); $(this).addClass("selected"); //console.log($(this).val()); console.log("new sel =>" + $(container).find(".selected").val()); } else { var container = $(this).closest("div.selection"); $(this).prop("checked", false); $(container).find(".selected").prop("checked", true); } });

提交回复
热议问题