根据第一个下拉框的选择,动态改变第二个是文本框还是下拉框;
<li> <div class="left">报修条件:</div> <div class="right"> <select class="checkarea" id="param_type" name="param_type" onchange="cardChange()" placeholder="客户证号" maxlength="32"> <option value="customerCode">客户证号</option> <!-- <option value="serialNo">机顶盒号</option> --> <option value="icCard">智能卡号</option> </select> </div> </li> <li> <div class="left"><span>*</span>报修证号:</div> <div class="right" id="textId" style="display: block"> <input type="text" class="checkarea" id="param_value" data-name="param_value" maxlength="32" readonly="readonly" value="<%=customercode%>"> </div> </li>
根据报修条件的下拉框选择值,改变报修证号的状态;给下拉框绑定一个事件cardChange()
function cardChange(){ //获取报修条件下拉框的value值 var selVal = $("#param_type").val(); var openId = "<%=openId%>"; var corpId = "<%=area_id%>"; var customercode = "<%=customercode%>"; $.ajax({ url:'getCardId.jspx?openId='+openId+'&corpId='+corpId, data:[], type:'POST', timeout:50000, contentType:'application/www-form-urlencoded;charset=utf-8', success:function (data){ if(data != ''){ var jsonDa = eval('('+data+')') //清空 $("#textId").empty(); //选择的值 if(selVal == "customerCode") { //选择客户证号 $("#textId").append("<input type='text' class='checkarea' id='param_value' data-name='param_value' maxlength='32' readonly='readonly' value='" + customercode + "'>"); } else if(selVal == "icCard") { //选择智能卡号 //根据id加入元素 var selectHtml = "<select class='checkarea' id='param_value' name='param_value'>"; for(var i = 0; i < jsonDa.length; i ++){ var map = jsonDa[i]; selectHtml += "<option value='"+ map.CARDNO +"'>" + map.CARDNO + "</option>"; } selectHtml += "</select>"; $("#textId").append(selectHtml); } } } }) }