解析javascript 实用函数的使用详解(2)

boxMove(box);

    if(showBg){
        objMask = document.createElement("div");
        objMask.className = "BoxMask";
        htmlRoot.appendChild(objMask);
        objMask.style.cssText += 'position:absolute;top:0; left:0;filter:Alpha(Opacity=50);opacity:0.5;background:#AAA;';

        objMask.style.zIndex = z_index -1;
        objMask.style.width =  htmlRoot.clientWidth + 'px';
        objMask.style.height = htmlRoot.scrollHeight + htmlRoot.scrollTop + 'px';
    }

    $(closeId).click(function(){
        showBox.hide();
        mybg.style.display = "none";
    });
    $('.closeBtn').click = function(){
        showBox.hide();
        mybg.style.display = "none";   
    };

}

function getFormQuery(formId){
/*生成查询字串*/
    formObj = document.getElementById(formId);
       var i, queryString = "", and = "", itemValue;
       for(i = 0; i<formObj.length; i++ ){
             var item = formObj[i];
              if ( item.name!='' ){
                     if(item.type == 'select-one'){
                         itemValue = item.options[item.selectedIndex].value;
                     }else if ( item.type=='checkbox' || item.type=='radio'){
                         if ( item.checked == false ){ continue; }
                         itemValue = item.value;
                     }else if ( item.type == 'button' || item.type == 'submit' || item.type == 'reset' || item.type == 'image'){
                         continue;
                     }else{
                          itemValue = item.value;
                     }
                   //  itemValue = escape(itemValue);
                     queryString += and + item.name + '=' + itemValue;
                     and="&";
                   //queryString += and + encodeURIComponent(item.name) + '=' +encodeURIComponent( itemValue);
              }
       }
       return queryString;
}

//定义js错误处理函数
onerror = errHandle;
function errHandle(msg,url,line){
    var txt=""
    txt = "本页中有错误!\n\n"
    txt += "错误: "+ msg +"\n"
    txt += "地址: " + url + "\n"
    txt += "行数: " + line + "\n\n"
    alert(txt);
    return false;
}


function setAutoWidth(id,width,size){
//最小或最大宽度
    var obj = document.getElementById(id);
    if(size=='max'){
        obj.style.width = (obj.clientWidth > width) ? width + "px" : "auto";
    }else{
        obj.style.width = (obj.clientWidth < width) ? width + "px" : "auto";
    }
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdgjjf.html