当前位置:编程学习 > JAVA >>

如何让多级联动菜单在添加时也联动

如何让多级联动菜单在添加时也联动

当我不选ifma时,MA Judgement 这个选项下拉菜单是灰色不可选的


当我选择IFMA为Yes时,MA Judgement 这个选项下拉菜单改为可选


但是我现在遇到的问题是,我点击了下面Add按钮,是凡我添加的不会跟着变化,请问怎么办,先谢谢各位大侠了!


--------------------编程问答-------------------- JS Select.js代码:

 var $ = function (id) {
     return "string" == typeof id ? document.getElementById(id) : id;
 };
 
function addEventHandler(oTarget, sEventType, fnHandler) {
     if (oTarget.addEventListener) {
         oTarget.addEventListener(sEventType, fnHandler, false);
     } else if (oTarget.attachEvent) {
         oTarget.attachEvent("on" + sEventType, fnHandler);
     } else {
         oTarget["on" + sEventType] = fnHandler;
     }
 };
 
function Each(arrList, fun){
     for (var i = 0, len = arrList.length; i < len; i++) { fun(arrList[i], i); }
 };
 
function GetOption(val, txt) {
     var op = document.createElement("OPTION");
     op.value = val; op.innerHTML = txt;
     return op;
 };
 
var Class = {
   create: function() {
     return function() {
       this.initialize.apply(this, arguments);
     }
   }
 }
 
Object.extend = function(destination, source) {
     for (var property in source) {
         destination[property] = source[property];
     }
     return destination;
 }
 

var CascadeSelect = Class.create();
 CascadeSelect.prototype = {
   //select集合,菜单对象
   initialize: function(arrSelects, arrMenu, options) {
     if(arrSelects.length <= 0 || arrMenu.lenght <= 0) return;//菜单对象
     
     var oThis = this;
     
     this.Selects = [];//select集合
     this.Menu = arrMenu;//菜单对象
     
     this.SetOptions(options);
     
     this.Default = this.options.Default || [];
     
     this.ShowEmpty = !!this.options.ShowEmpty;
     this.EmptyText = this.options.EmptyText.toString();
     
     //设置Selects集合和change事件
     Each(arrSelects, function(o, i){
         addEventHandler((oThis.Selects[i] = $(o)), "change", function(){ oThis.Set(i); });
     });
     
     this.ReSet();
   },
   //设置默认属性
   SetOptions: function(options) {
     this.options = {//默认值
         Default:    [],//默认值(按顺序)
         ShowEmpty:    false,//是否显示空值(位于第一个)
         EmptyText:    "请选择"//空值显示文本(ShowEmpty为true时有效)
     };
     Object.extend(this.options, options || {});
   },
   //初始化select
   ReSet: function() {
   
     this.SetSelect(this.Selects[0], this.Menu, this.Default.shift());
     this.Set(0);
   },
   //全部select设置
   Set: function(index) {
     var menu = this.Menu
     
     //第一个select不需要处理所以从1开始
     for(var i=1, len = this.Selects.length; i < len; i++){
         if(menu.length > 0){
             //获取菜单
             var value = this.Selects[i-1].value;
             if(value!=""){
                 Each(menu, function(o){ if(o.val == value){ menu = o.menu || []; } });
             } else {  menu = []; }
             
             //设置菜单
             if(i > index){ this.SetSelect(this.Selects[i], menu, this.Default.shift()); }
         } else {
             //没有数据
             this.SetSelect(this.Selects[i], [], "");
         }
     }
     //清空默认值
     this.Default.length = 0;
   },
   //select设置
   SetSelect: function(oSel, menu, value) {
     oSel.options.length = 0; oSel.disabled = false;
     if(this.ShowEmpty){ oSel.appendChild(GetOption("", this.EmptyText)); }
     if(menu.length <= 0){ oSel.disabled = true; return; }
     
     Each(menu, function(o){
         var op = GetOption(o.val, o.txt ? o.txt : o.val); op.selected = (value == op.value);
         oSel.appendChild(op);
     });    
   }
};

 
window.onload=function(){
     var menu = [
         {'val': '0', 'txt': ' '},
         {'val': '1', 'txt': 'Yes', 'menu': [
             {'val': '1', 'txt': 'Yes'},
             {'val': '0', 'txt': 'No'}
         ]}

     ];
     
     var sel=["sel1", "sel2"];
     var val=[" "," "];
     var cs = new CascadeSelect(sel, menu, { Default: val });
     $("btnA").onclick=function(){cs.ShowEmpty=!cs.ShowEmpty;}

 }
--------------------编程问答-------------------- JSP:部分代码:


               <tr>
                  <td align="left" width="100">
                    <B>If MA :</B>
                  </td>
                  <td align="left">
                    <select  name="ifma" id="sel1" style="width:70px;height:25px;font-family:Arial;">
</select>
                    <font color="#e40707">If not MA, please don't select.</font>
                  </td>
                </tr>
                <tr>
                  <td align="left"width="100">
                    <B>Service Type :</B>
                  </td>
                  <td align="left" height="25">
                     <input name="service_type" value="1" type="radio" checked><B>Onsite</B> <input name="service_type" value="0" type="radio"><B>Beanch</B>
                  </td>
                </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td>
          <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
                <tr>
                  <td>
                    <table id="tb" width="750" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#f5f5f5"  valign="top" style="margin-top:5px;"> 

                            <tr bgcolor="#c5c5c5" height=25>
                              <td width="10%" align="center"><B>Item</B></td> 
                              <td width="15%" align="center"><B>Part</B></td> 
                              <td width="25%" align="center"><B>CT Number</B></td> 
                              <td width="15%" align="center"><B>Judgement</B></td> 
                              <td width="18%" align="center"><B>MA Judgement</B></td> 
                              <td width="15%" align="center"><B>Comment</B></td> 
                            </tr> 
    <tr id="r1">
                              <td align="center">/</td>
                              <td align="center">
                                <select name="part" style="height:25px;font-family:Arial;">
                                       <option value=""></option>
                                       <option value="MBD">MBD</option>
                                       <option value="HDD">HDD</option>
                                       <option value="ODD">ODD</option>
                                       <option value="ADP">ADP</option>
                                       <option value="BAT">BAT</option>
                                       <option value="RAM">RAM</option>
                                       <option value="KBD">KBD</option>
                                       <option value="PSU">PSU</option>
                                </select>
                              </td>
                              <td align="center"><input type="text" name="ct_num" style="width:160px;height:25px;font-family:Arial;" autocomplete="off"></td>
                              <td align="center"><select name="judgement" style="height:25px;font-family:Arial;"><option value="1">Yes</option><option value="0" style="background-color:#e40707;">No</option></select></td>
                              <td align="center">
                                <select name="ma_judgement" id="sel2"  style="width:48px;height:25px;font-family:Arial;">
</select><input type="hidden" name="ma_judgement" value="1">
                              </td>
                              <td align="center">
                                <textarea cols="40" rows="2" name="comment" style="font-family:Arial;font-size:12px;"></textarea>
                              </td>
    </tr>
                    </table>
                  </td>
                </tr>
                <tr>
                 <td align="center">
                   <table width="750" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#f5f5f5" valign="top" style="margin-top:2px;">
                         <tr>
                           <td width="10%"> </td>
                           <td width="15%"> </td>
                           <td width="15%"> </td>
                           <td width="18%"> </td>
                           <td width="15%" align="right">
                             <input type="button" onClick="add();" value="Add" style="font-family:Arial;font-weight:bold;"/>
             <input name="button" type="button" onClick="deletes();" value="Delete" style="font-family:Arial;font-weight:bold;"/>
                           </td>
                         </tr>
                   </table>
                 </td>
               </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td>
          <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0" style="margin-top:10px;">
                <tr>
                  <td align="left">
                    <input type="submit" name="submit" value="Submit" style="font-family:Arial;font-weight:bold;">
                  </td>
                </tr>
          </table>
        </td>
      </tr>
</table>
</form>
<script language="javascript">
var tb=document.getElementById("tb");
var i=1;
function add(){
var mytr=tb.insertRow();
mytr.setAttribute("id","r"+i);
var mytd_1=mytr.insertCell();
var mytd_2=mytr.insertCell();
var mytd_3=mytr.insertCell();
var mytd_4=mytr.insertCell();
var mytd_5=mytr.insertCell();
var mytd_6=mytr.insertCell();

mytd_1.style.backgroundColor='#f5f5f5';
mytd_2.style.backgroundColor='#f5f5f5';
mytd_3.style.backgroundColor='#f5f5f5';
mytd_4.style.backgroundColor='#f5f5f5';
mytd_5.style.backgroundColor='#f5f5f5';
mytd_6.style.backgroundColor='#f5f5f5';

mytd_1.innerHTML="<center><input type='checkbox' name='ck' value='"+i+"'></center>";
mytd_2.innerHTML="<center><select name='part' id='part"+i+"' style='width:55px;height:25px;font-family:Arial;'><option value=''></option><option value='MBD'>MBD</option><option value='HDD'>HDD</option><option value='ODD'>ODD</option><option value='ADP'>ADP</option><option value='BAT'>BAT</option><option value='RAM'>RAM</option><option value='KBD'>KBD</option><option value='PSU'>PSU</option></select></center>";
mytd_3.innerHTML="<center><input type='text' name='ct_num' id='ct_num"+i+"' style='width:160px;height:25px;font-family:Arial;' autocomplete='off'></center>";
mytd_4.innerHTML="<center><select name='judgement' id='judgement"+i+"' style='width:48px;height:25px;font-family:Arial;'><option value='1'>Yes</option><option value='0'>No</option></select></center>";
mytd_5.innerHTML="<center><select name='ma_judgement' id="sel2" style='width:48px;height:25px;font-family:Arial;'></select></center>";
mytd_6.innerHTML="<center><textarea cols='40' rows='2' name='comment' id='comment"+i+"' style='font-family:Arial;font-size:12px;'></textarea></center>";

i++;
}
function deletes() {
var ok=document.getElementsByName("ck");
for(var k=2;k<ok.length+2;k++){
if(ok[k-2].checked==true){
tb.deleteRow(k);
            k=k-1;
        }
    }
}

</script> --------------------编程问答-------------------- 判断是否有值,是yes就让他可操作,无值就disabled。 --------------------编程问答--------------------
引用 3 楼 fangmingshijie 的回复:
判断是否有值,是yes就让他可操作,无值就disabled。

怎么判断呢?关键我添加那里是做的循环数组 --------------------编程问答-------------------- 有没有了解的,谢谢了!在线等! --------------------编程问答-------------------- 自己顶下!顶顶!
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,