select2的使用及問題

  這個插件是基於Select的擴展插件,可以提供更加豐富的功能和用戶體驗,它的github官網地址爲:https://select2.github.io/,具體的使用案例,能夠參考地址:https://select2.github.io/examples.htmlcss

  select2是對select進行美化,網上也有不少列子。在項目開發中,遇到了使用select2進行下拉選擇,可是下拉選項仍是必填項,在網上找了好多解決辦法都不行,最後採起的追加,解決了!!    html

必填校驗: git

$("#nativePlace").select2();
$("#userId").select2();
$("#studyMajor").select2();
$("#nation").select2();
var str= "<div class='tip-yellowsimple' id='nativePlace_error' onclick=\"hide_error(this,'nativePlace')\" style='left: 655px; top: 148px;cursor: pointer;visibility: hidden;'>"+
"<div class='tip-inner tip-bg-image'>"+
"<label class='error'>不能爲空</label>"+
"</div>"+
"<div class='tip-arrow tip-arrow-left' style='visibility: inherit;position: absolute;overflow: hidden;font: 1px/1px sans-serif;'></div>"+
"</div>"+
"<div class='tip-yellowsimple' id='userId_error' onclick=\"hide_error(this,'userId')\" style='left: 352px; top: 96px;cursor: pointer;visibility: hidden;'>"+
"<div class='tip-inner tip-bg-image'>"+
"<label class='error'>不能爲空</label>"+
"</div>"+
"<div class='tip-arrow tip-arrow-left' style='visibility: inherit;position: absolute;overflow: hidden;font: 1px/1px sans-serif;'></div>"+
"</div>"+
"<div class='tip-yellowsimple' id='nation_error' onclick=\"hide_error(this,'nation')\" style='left: 948px; top: 96px;cursor: pointer;visibility: hidden;'>"+
"<div class='tip-inner tip-bg-image'>"+
"<label class='error'>不能爲空</label>"+
"</div>"+
"<div class='tip-arrow tip-arrow-left' style='visibility: inherit;position: absolute;overflow: hidden;font: 1px/1px sans-serif;'></div>"+
"</div>";
/* "<div class='tip-yellowsimple' id='studyMajor_error' onclick=\"hide_error(this,'studyMajor')\" style='left: 948px; top: 178px;cursor: pointer;'>"+
"<div class='tip-inner tip-bg-image'>"+
"<label class='error'>不能爲空</label>"+
"</div>"+
"<div class='tip-arrow tip-arrow-left' style='visibility: inherit;position: absolute;overflow: hidden;font: 1px/1px sans-serif;'></div>"+
"</div>"+ */
$("body").append(str);

$(window).resize(function(){
if($("#nativePlace_error").css("visibility") == "visible"){
check("nativePlace",658+($(document).width()-1183)/2+"px");
}
if($("#userId_error").css("visibility") == "visible"){
check("userId",360+($(document).width()-1183)/2+"px");
}
if($("#nation_error").css("visibility") == "visible"){
check("nation",960+($(document).width()-1183)/2+"px");
}
});

$("#nativePlace").on("select2-focus", function(e) { check("nativePlace",658+($(document).width()-1183)/2+"px");});
$("#userId").on("select2-focus", function(e) { check("userId",360+($(document).width()-1183)/2+"px");});
/* $("#studyMajor").on("select2-focus", function(e) { check("studyMajor","948px");}); */
$("#nation").on("select2-focus", function(e) { check("nation",960+($(document).width()-1183)/2+"px");});
})github

清空:app

$("#nation").val(null).trigger("change");ide

相關文章
相關標籤/搜索