Jquery chosen动态设置值实例介绍 select Ajax动态加载数据 设置chosen和获取他们选中的值

for (var i = 0; i < obj.length; i++)
$("#selectnum" + nid).append("<option myid='" + obj[i].ID + "' myname='" + obj[i].Name + "'>" + obj[i].Name + "</option>");

$("#selectnum" + nid).trigger("liszt:updated");
$("#selectnum" + nid).chosen(); //変更このさまシ

--------------------------

//bug begin
mytid = $("#selectnum" + k).find("option:selected").attr("myid");
if (mytid == "undefined" || mytid == undefined)
mytid = "";

mytname = $("#selectnum" + k).find("option:selected").attr("myname");
if (mytname == "undefined" || mytname == undefined)
mytname = "";

isenum = $("#selectnum" + k).attr("myenumid"); //获取次字段是否为枚举

temps = temps + mytid + "#";
temps = temps + mytname + "#";
temps = temps + isenum;
//bug end
objarray.push(temps);

定义变量相加  不热会出现bug获取的为undefined

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="chosen/chosen.jquery.js" type="text/javascript"></script>

应用JS文件

<select class="chzn-select" data-placeholder="Choose a Country" style="width:350px;" tabindex="1">
<option value=""></option>
<option value="United States">United States</option>
<option value="United Kingdom">United Kingdom</option>
<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
</select>

class设这为chzn-select

初始化:$(".chzn-select").chosen();

对select进行操作时候需注意如下:先删除外部套用的层在经常操作,最后在加上$(".chzn-select").chosen();

var selectObj = $("#slectplat");
selectObj.parent().children().remove('div');
selectObj.removeClass();
$("#slectplat").val(_plat);
selectObj.addClass("chzn-select");
selectObj.chosen();

上一篇:Head First Servlets & JSP 学习笔记 第十一章 —— Web应用部署


下一篇:【BZOJ4445】[Scoi2015]小凸想跑步 半平面交