JS CheckBox事件

时间:2025-01-25 18:24:34

 <%@ page language="java" import=".*" pageEncoding="UTF-8"%>
<%@ page import="" %>
<%@ page import="" %>
<%@ page import="" %>
<%@ page import="" %>
<%@ page import="" %>
<%@ include file="../common/"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head> 
    <title>部门列表&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</title>
    <SCRIPT src="<%=()%>/views/common/scripts/"></SCRIPT>  
     <LINK rel="stylesheet" type="text/css" href="<%=()%>/views/common/styles/">
     <script src='<%=()%>/views/common/scripts/'></script>
     <%
       Map para = new HashMap();
       UserService userService = (UserService)(UserConstants.USERSERVICE_BEAN_KEY);
       String typ = "Department";
       List dfiItemData = (typ);
       List userList = userService.select4Group();
       ("dfiItemData",dfiItemData);
       ("userList",userList);
       ("fistQuery","fistQuery");
     %>
          <script type="text/javascript" language="Javascript">
         var winWidth=0;
         var winHeight=0; 
         var data = "";    
         function callback(){
            var defItem = ("defItem1");
           
            var a=0;
          for(var i = 0;i<;i++){
              if(defItem[i].checked){
                  ++a;
                  if(defItem[i].value=="undefined") defItem[i].value="";

               if(data=="" && defItem[i].value!=""){
                     data=defItem[i].value;
           }else if(defItem[i].value!=""){
              data+=","+defItem[i].value;
          }
        }       
          
         }
            =data;
            ();
            ();
       }
      
     </script>
<script language='javascript'>

var imgPath = '<%=()%>/images/';
var imgBlank = imgPath + 'arrow_002.jpg';
var imgFolderClose = imgPath + '';
var imgFolderOpen = imgPath + '';
var imgText = imgPath + '';
var targetFrame = '_self';
var clSelected = '#DD0000';
var clUnSelected = '#999999';
var g_hasCheckbox = false;

var g_checkboxName = 'selItem';
var g_checkboxNameLevel = true; //如果有必要,可以不同层次的不同

var g_readonly = false;

var curNode;

function Node(aId, aText){
    = aId;
    = false;
    = aText;
    = new Array();
    = 0;
    = false;
    = 0;
    = null;
}

= function(aChildNode){
    [++] = aChildNode;
}


function dispNode(aNode){
   //var atxt = ! ? '<font style="cursor:hand" οnclick="expand()">' + + '</font>' : '<a href="' + + '" target="' + targetFrame + '" οnclick="change(this);">' + + '</a>';
    var atxt = '<font style="cursor:hand" οnclick="expand()">' + + '</font>';
    if (g_hasCheckbox) atxt = '<input type="checkbox" style="width:25px;" name="defItem1" value="' + + '" οnclick="return selectChanged(this)" ' + ( ? 'checked' : '') + '>' + atxt;
    if ( > 0){
        var folderImg = ? imgFolderOpen : imgFolderClose;
        //('<img style="cursor:hand" οnclick="expand(this)" src="<%=()%>/images/">' + atxt);
        ('<img style="cursor:hand" οnclick="expand(this)" src="'+folderImg+'">' + atxt);
    } else
        ('<img src="' + imgText + '">' + atxt);
}


function selectChanged(obj){

    if (g_readonly) return false;
    if (){ // 选择所有父节点,因此需要增加 属性


                  var objParent = ;
                  if (objParent || == 'DIV'){

                      var nodeParent = eval((3)); // 是 'div' +

                      while (nodeParent){
                var objImg = ();
                = true;
                nodeParent = ;
                      }
                  }
    }

    var divId = 'div' + ;
    var divObj = (divId);

    if (!divObj) return;
    var childs = ('INPUT');
    for (var i = 0; i < ; i++) childs[i].checked = ;
}

function change(obj){
    if (curNode) = clUnSelected;
    curNode = obj;
    = clSelected;
}

function expand(obj){
    while ( != 'IMG') obj = ;
    var divId = 'div' + ;
    var divObj = (divId);

    if (divObj) with (divObj){
        if ( == 'none'){
            = imgFolderOpen;
            = 'block';
        } else {
            = imgFolderClose;
            = 'none';
        }
    }
}

function makeTree(aNode, aLevel){
    if (aLevel == 0){
        = true; //默认根节点展开

        dispNode(aNode);
    }
    var dispMode = ? 'block' : 'none';

    ('<div style="display:' + dispMode + '">');
    var tmpNode;
    for (var i=0; i < ; i++){
        tmpNode = [i];
        = aNode;
        = aLevel + 1;

        for (var j=0; j <= aLevel; j++)
            ('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp');

        dispNode(tmpNode);
        ('<br>');

        if ( > 0) makeTree(tmpNode, aLevel+1);
    }
     ('</div>');
}
</script>

 <SCRIPT LANGUAGE="JavaScript">
                       g_readonly = false; //<!-- 控制checkbox的可编辑状态 %=isShowState% -->

g_hasCheckbox = true;

g_checkboxName = 'selItemB';

g_checkboxNameLevel = true;

 

//<!-- 从数据库获取数据,生成树 %=()%-->

var node_root = new Node('node_root', '部门列表');

<%
  int i=0;
  int j=0;
  for(Iterator iter = ();();){
    DfiItemDataDTO dataDTO = (DfiItemDataDTO)(); 
      %>
       var node_<%=i%> = new Node('node_<%=i%>', '<%=dataDTO.getDefItem1()%>');
       node_root.addChild(node_<%=i%>);
      <%
      for(Iterator iter1 = ();();){
        UserDTO userDTO = (UserDTO)(); 
        if(().equals(dataDTO.getDefItem1())){
      %>
        var nodeCH_<%=j%>= new Node('nodeCH_<%=j%>', '<%=()%>');
        nodeCH_<%=j%>.link='<%=()%>';
        node_<%=i%>.addChild(nodeCH_<%=j%>);
      <%
      }
      j++;
      }
     
      i++;
    }
%>
    makeTree(node_root , 0);
  </SCRIPT>
     <script src='<%=()%>/views/common/scripts/'></script>
  </head>
  <body>
  <TABLE bgcolor="#638EA5" border="0" width="100%" cellspacing="1" cellpadding="0">
    <TR align="center">
        <TD><html:submit value=" OK " οnclick="callback()" style="width: 50px;"/></TD>
     </TR>
  </TABLE>
  
  </body>
</html>