<select class="form-control" id="IllegalTimeInterval" name="IllegalTimeInterval">
<option value="0"></option>
<option value="1">每1个小时展示</option>
<option value="2">每2个小时展示</option>
</select>
$("#IllegalTimeInterval").val(data.Result.IllegalTimeInterval);
//多选框,去掉multiple可以改造成单选框,这个select引入chosen会有搜索效果
<div class="col-sm-8"> <select class="multiselect form-control" multiple="multiple" id="EventType" name="EventType"> <option value="">请选择</option> </select> </div> $("#EventType").chosen({ "100%", no_results_text: "没有匹配结果", placeholder_text: "请选择事件类型", search_placeholder: "事件类型" }); EventTypeForm = function () { //初始化时执行一次,给select下拉框动态赋值 $.ajax({ type: "get", url: "/api/Common/DictManager/GetDictByDictTypeID", data: { "id": "1013" }, dataType: "json", success: function (data) { if (data.HasError) { console.log(data.HasError); return; } else { $laneSelect = $('#EventType').empty(); var temp = '<option value="{0}">{1}</option>'; for (var j in data.Result) { $(temp.format(data.Result[j].DictionaryNo, data.Result[j].Value)).data('src', data.Result[j]).appendTo($laneSelect); } $("#EventType").trigger("chosen:updated"); } } }); },
select获取option文本值
单选
var s = $("#EventType").find("option:selected").text();
$('#EventType option:selected').text();//选中的文本
$('#EventType option:selected') .val();//选中的值
$("#EventType ").get(0).selectedIndex;//索引
多选
var productArray = new Array();
$.each($("#EventType").find("option:selected"), function(index, obj) {
productArray.push($(obj).text());
});
$.each($("#EventType").find("option:selected"), function(index, obj) {
productArray.push($(obj).text());
});
var productStr=productArray.join(",");