标签:
data-plans=[{"id":240,"title":"\u6768\u5e06-\u4f5f\u91d1\u5e7f-\u7269\u7406\u5b66\u4e60\u8ba1\u5212","user_package_id":1,"progress":0}]
<div class="input-group col-xs-12" id="time" style="margin-bottom:5px;"> <span class="input-group-addon"><span class="must_edit">*</span>教学计划</span> <select class="form-control" id="selOption" name="id"> </select> </div>
$(document.body).on("click", ".btn-change", function () {
var $this = $(this);
var $elem = $("#change_time");
// $elem.find("[name=appointment_time]").val($this.data(‘appointment_time‘));
var plans = $(this).attr("data-plans");
// var obj = JSON.parse(plans);//注释部分可获得data-plans 的id,title
// alert(obj[0].id);
// alert(obj[0].title);
var plan =JSON.stringify($this.data(‘plans‘)); //将数据化为json字符串
// console.log(plans);
//
$(‘#selOption‘).empty();
var obj =eval(plan);//把json字符串转为对象(数组的感觉)
for(var i=0;i<obj.length;i++){
var opt=$(‘<option value=‘+obj[0].id+‘>‘+obj[0].title+‘</option>‘);
$(‘#selOption‘).append(opt);
}
});
http://q.cnblogs.com/q/57961/
标签:
原文地址:http://www.cnblogs.com/Secretmm/p/5694736.html