- var switchStatus = function(str){
- _this = this;
- _this.str = str
- _this.pId = document.getElementById(str);
- _this.flag=true;
- _this.init();
- }
- switchStatus.prototype = {
- clk:function(arg){
- if(_this.flag){
- _this.fst();
- }else if(!_this.flag&&arg.getElementsByTagName("a")[0].innerhtml != "申请休息"){
- _this.scd(arg);
- }else{
- _this.appRest(arg);
- }
- },
- fst:function(){
- for (var i = 0; i < _this.sLilength; i++) {
- _this.sLi[i].className = "db";
- };
- _this.flag = false;
- },
- scd:function(arg){
- for (var i = _this.sLilength-1; i >=0; i--) {
- // alert(i)
- _this.sLi[i].className = "dn"
- var ap = _this.sUl.appendChild(arg);
- _this.flag = true;
- }
- arg.className = "db";
- },
- dft:function(){
- for (var i = _this.sLilength-1; i >=0; i--) {
- _this.sLi[i].className = "dn"
- _this.flag = true;
- }
- _this.sUl.lastChild.className = "db";
- },
- appRest:function(arg){
- if(confirm("确定还是取消?")){
- _this.scd(arg)
- }else{
- this.dft();
- }
- },
- init:function(str){
- _this.sUl = _this.pId.getElementsByTagName("ul")[0]
- _this.sLi = _this.sUl.getElementsByTagName("li")
- _this.sLilength = this.sLi.length;
- var _html = document.getElementsByTagName("html")[0];
- _html.onclick = function(event){
- var e=(event) ? event : window.event;
- var target = (e.target)?e.target:e.srcElement;
- var ocBox = "";
- if(target.nodeName == 'A') {
- var ocBox = target.parentNode.parentNode.parentNode;
- }
- if(target.nodeName == 'LI') {
- var ocBox = target.parentNode.parentNode;
- }
- if(target.nodeName == 'UL') {
- var ocBox = target.parentNode;
- }
- if(ocBox.id != _this.str) {
- _this.dft();
- }
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/070820135013.html
来源: http://www.codesnippet.cn/detail/070820135013.html