Javascript Dropdownlist取消确认后选择的默认值

Javascript Dropdownlist取消确认后选择的默认值,javascript,jquery,drop-down-menu,Javascript,Jquery,Drop Down Menu,我的下拉列表加载了以下内容: @EnumDropDownListFor(x=>x.field,新的{@class=“form control select”,type=“text”,id=“dropdownlist”}) 给你: $("#dropdownlist").on("change",function () { var asdf= document.getElementById("#dropdownlist"); swal({...}

我的下拉列表加载了以下内容: @EnumDropDownListFor(x=>x.field,新的{@class=“form control select”,type=“text”,id=“dropdownlist”})

给你:

    $("#dropdownlist").on("change",function () {
            var asdf= document.getElementById("#dropdownlist");
            swal({...},function (isConfirm) {
                  if (isConfirm) {
    //post url
    }
    else{
        $("#dropdownlist option:first").attr('selected','selected');  //this will do the job for you.
    }
给你:

    $("#dropdownlist").on("change",function () {
            var asdf= document.getElementById("#dropdownlist");
            swal({...},function (isConfirm) {
                  if (isConfirm) {
    //post url
    }
    else{
        $("#dropdownlist option:first").attr('selected','selected');  //this will do the job for you.
    }

默认值您指的是下拉列表的第一个
?是第一个值默认值您指的是下拉列表的第一个
?是第一个value@alettin,这是如何帮助您的。不起作用。否则{alert(“warning”);$(“#dropdownlist option:first”).attr('selected','selected');//这将为您完成任务。}警报工作,但代码不工作实际ı在新选择值之前需要选定值我不理解这一点实际ı在新选择值之前需要选定值我的声誉低于15:(@alettin,这对您有何帮助。不工作。否则{alert(“warning”);$(“#dropdownlist option:first”).attr('selected','selected');//这将为您完成任务。}警报工作,但代码不工作实际ı在新选择值之前需要选定值我不理解这一点实际上ı在新选择值之前需要选定值我的声誉小于15:(