jquery操作select绑定change事件

(function(r){
r.init = function(){
// 页面容器(jQuery对象)
var c = this.container;
// 查询表单(jQuery对象)
var form = this.getForm();
// 打开页面所发请求地址
var url = this.getUrl();
// 在此处实现参数设置
// ---------------------------------
//航班信息工作量确认给查询条件日期设置默认值
return true;
},
// 初始化成功后执行此方法
r.success = function(){
$("input:[name='m:equipment_infor:sec_classify']").remove();
initSelect();
createSelect();
},
// 初始化失败后执行此方法
r.error = function(){
}
})(getBiz());
var data=[
{
id:2,
name: '设施设备',
children: [{
id:21,
name: '特种车辆'
},
{ id:22,
name: '维修梯'
},
{
id:23,
name: '飞机轮挡'
},
{
id:24,
name: '飞机牵引杆'
},
{
id:25,
name: '飞机轮挡推车'
},
{
id:26,
name: '千斤顶'
}
]
},
{
id:1,
name: '工具',
children: [{
id:11,
name: '航线维修常用工具'
},
{
id:12,
name: '放燃油沉淀工具'
},
{
id:13,
name: '转弯旁通销安全销'
},
{
id:14,
name: '电筒'
},
{
id:15,
name: '对讲机'
},
{
id:16,
name: '反光锥'
},
{
id:16,
name:'勤务耳机'
},
{
id:17,
name: '指挥棒'
},
{
id:18,
name: '换轮工具'
}
]
},
{
id:3,
name: '计量器具',
children: [{
id:31,
name: '便携式冰点仪'
},
{
id:32,
name: '飞机轮胎气压表'
},
{
id:33,
name: '游标卡尺'
},
{
id:34,
name: '扭矩扳子'
},
{
id:35,
name: '氮气瓶压力表'
}]
},
{
id:4,
name: '器材',
children: [{
id:41,
name: '油料'
},
{
id:42,
name: '飞机除冰防冰液'
},
{
id:43,
name: '氮气瓶'
}]
}
]
var queryChildren = function(id){
var children = null;
for(var i=0;i<data.length;i++){
if(data[i].id==id){
children = data[i].children;
return children;
}
}
}
var initSelect=function(){
var html="<select name='m:equipment_infor:sec_classify'>";
var s = $("select[name='m:equipment_infor:classify']");
var data = queryChildren(s.val());
$(data).each(function(){
html=html+"<option value="+this.id+">"+this.name+"</option>"
})
html=html+"</select>"; 
$(".ew-c-formTbl tr").first().after("<tr id='sec_type'><td align='right'>二级分类</td><td>"+html+"</td></tr>");
var sec_text = $("select[name='m:equipment_infor:sec_classify']").find("option:selected").text();
$("input:[name='m:equipment_infor:sec_classifyname']").val(sec_text);
$("select[name='m:equipment_infor:sec_classify']").change(function(){
var sec_text = $("select[name='m:equipment_infor:sec_classify']").find("option:selected").text();
$("input:[name='m:equipment_infor:sec_classifyname']").val(sec_text);
});
};
var createSelect = function(id){
$("select[name='m:equipment_infor:classify']").change(function(){
$("#sec_type").remove();
var html="<select name='m:equipment_infor:sec_classify'>";
var data = queryChildren($(this).val());
$(data).each(function(){
html=html+"<option value="+this.id+">"+this.name+"</option>"
})
html=html+"</select>";
$(".ew-c-formTbl tr").first().after("<tr id='sec_type'><td>二级分类</td><td>"+html+"</td></tr>");
});

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值