现在的位置: 首页 > 综合 > 正文

common.js 搜集整理

2012年06月24日 ⁄ 综合 ⁄ 共 10153字 ⁄ 字号 评论关闭

function ResizeImage(ImgD,FitWidth,FitHeight)

{    
    var image=new Image();
    image.src=ImgD.src;
    var wb=image.width/FitWidth;
    var hb=image.height/FitHeight;
    var b=wb>=hb?wb:hb;
    if(b>1)
    {
        ImgD.width=image.width/b;        
        ImgD.height=image.height/b;
    }
    else
    {
        ImgD.width=image.width;        
        ImgD.height=image.height;
    }
 }
//获取Dom对象
function $$(id)
{
    return document.getElementById(id);
}
//设为首页
function SetHomePage(obj,url) 
{
    obj.style.behavior = "url(#default#homepage)";
    obj.setHomePage(url);
}
//加入收藏夹
function AddFavorite(url, title) 
{
    window.external.addFavorite(url,title);
}
//新开普通窗口
function WindowOpen(url, w, h, b) 
{
    var s = "scrollbars=" + b + ",";
    s += "toolbar=no,resizable=yes,status=yes," + "top=" + (screen.availHeight - h) / 2 + ",height=" + h + ",left=" + (screen.availWidth - w) / 2 + ",width=" + w;
    window.open(url, "_blank", s);
}
//新开模式窗口
function ShowDialog(url, w, h) 
{
    if (document.all) 
    {
      return window.showModalDialog(url, null, "dialogWidth:" + w + "px;dialogHeight:" + h + "px;scroll=no;status:no;help:no");
    } 
    else 
    {
        window.open(url, null, "width=" + w + ",height=" + h + ",menubar=no,toolbar=no,location=no,scrollbars=no,status=no,modal=yes");
    }
}
//关闭窗口
function WinClose()
{
    window.opener = null;
    window.open("","_self"); 
    window.close(); 
}
//刷新父窗口
function RefreshParent()
{
    if (window.opener != null && (!window.opener.closed)) 
    {
  var parentForm = window.opener.document.forms[0];
  if (parentForm!=null) 
  {
      parentForm.submit();
  }
 }
}
//iframe自适应高度
function ResizeFrameHeight(frmName)
{   
    var frm = $$(frmName);   
    var subWeb = document.frames ? document.frames[frmName].document : frm.contentDocument;   
    if(frm != null && subWeb != null) 
    {
        frm.height = subWeb.body.scrollHeight;
        if(frm.height < 500)
        {
            frm.height = document.body.clientHeight;
        }
    }
}   
//iframe自适应高度
function ResizeFrameHeight2(frmName)
{   
    var frm = $$(frmName);   
    var subWeb = document.frames ? document.frames[frmName].document : frm.contentDocument;   
    if(frm != null && subWeb != null) 
    {
        frm.height = subWeb.body.scrollHeight;
    }
//更换验证码
function ChangeImg(path)
{
    $$('checkCode').src=path + 'Inc/CheckCode.ashx?id='+Math.random();
}
//解析生成原始Google地图
function ShowAddress(map,xId,yId,zId,address) 
{
    var geocoder = new GClientGeocoder(); 
    geocoder.getLatLng(address,function(point)
    { 
        if (!point)
        { 
            alert("无法解析:" + address); 
        } 
        else 
        { 
            map.setCenter(point, 15);//设置地图中心点和缩放级别
            map.addControl(new GLargeMapControl());//添加完整的缩放控件
            map.addControl(new GMapTypeControl());//添加地图类型控件
            map.addControl(new GScaleControl());//添加比例尺控件
            map.enableScrollWheelZoom();//启用鼠标滚轮缩放地图
            //添加单击事件,获取点击坐标和缩放级别
            GEvent.addListener(map, "click", function(marker,point)
            {
                if(point)
                {
                    $$(xId).value = point.lng();//获取经度坐标
                    $$(yId).value = point.lat();//获取纬度坐标
                    $$(zId).value = map.getZoom();
                }
                if (marker) 
                {    
                    map.removeOverlay(marker);  
                } 
                else 
                {    
                    map.clearOverlays();
                    map.addOverlay(new GMarker(point));  
                }
            }); 
        } 
    }); 
}
//初始化Google地图并标注位置
function ShowMarker(map,posX,posY,zoomSize,name,isAdd)
{
    var point = new GLatLng(posY,posX);
    var marker = new GMarker(point);
    
    if(isAdd)
    {
        map.setCenter(point,zoomSize);
        map.addControl(new GLargeMapControl());//添加完整的缩放控件
        map.addControl(new GMapTypeControl());//添加地图类型控件
        map.addControl(new GScaleControl());//添加比例尺控件
        map.enableScrollWheelZoom();//启用鼠标滚轮缩放地图
    }
    else
    {
        setTimeout(function(){map.setCenter(point,zoomSize);},1000);//设置地图中心点和缩放级别
    }
    
    map.addOverlay(marker);//添加标注点
    marker.openInfoWindowHtml(name);//显示标注信息
}
//加载图片
function LoadImg(ImgD,FitWidth,FitHeight)
{   
    var image=new Image();
    
    image.src=ImgD.src;
    var wb=image.width/FitWidth;
    var hb=image.height/FitHeight;
    var b=wb>=hb?wb:hb;
    if(b>1)
    {
        ImgD.width=image.width/b;        
        ImgD.height=image.height/b;
    }
    else
    {
        ImgD.width=image.width;        
        ImgD.height=image.height;
    }
 }
 
//树形控件单选框联动
function OnTreeNodeChecked() 
    var ele = window.event.srcElement; 
    if(ele.type=='checkbox') 
    { 
        var childrenDivID = ele.id.replace('CheckBox','Nodes'); 
        var div = $$(childrenDivID); 
        if(div==null)return; 
        var checkBoxs = div.getElementsByTagName('INPUT'); 
        for(var i=0;i<checkBoxs.length;i++) 
        { 
            if(checkBoxs[i].type=='checkbox') 
            checkBoxs[i].checked=ele.checked; 
        } 
    } 
}
//切换左侧菜单
function ShowMenus(obj)
{
    if(obj.alt == "隐藏菜单")
    {
        $$("leftMenus").style.display = "none";
        obj.src = "../Images/Admin/jt.gif";
        obj.alt = "显示菜单";
    }
    else
    {
        $$("leftMenus").style.display = "block";
        obj.src = "../Images/Admin/jt.jpg";
        obj.alt = "隐藏菜单";
    }
}
//切换显示的层
function ShowDiv(index)
{
    var objs = document.getElementsByName("tdm");
    var divs = document.getElementsByName("dm");
    var imgs = document.getElementsByName("ig");
    
    for(var i = 0; i < divs.length; i++)
    {
        divs[i].style.display = "none";
        objs[i].style.background = "url(../Images/Soft/dtceopen.jpg)";
        imgs[i].src = "../images/Soft/j2.gif";
            
        if(i == index)
        {
            divs[i].style.display = "block";
            objs[i].style.background = "url(../Images/Soft/dtceopen1.jpg)";
            imgs[i].src = "../images/Soft/j1.gif";
        }
    }
}
//后台验证登录
function CheckLogin()
{
    var isOk = true;
    if(form1.txtLoginName.value == "")
    {
        alert("请输入用户名!");
        form1.txtLoginName.focus();
        isOk=false;
    }
    else if(form1.txtPassword.value == "")
    {
        alert("请输入登录密码!");
        form1.txtPassword.focus();
        isOk=false;
    }
    else if(form1.txtCheckCode.value == "")
    {
        alert("请输入验证码!");
        form1.txtCheckCode.focus();
        isOk=false;
    }
    
    return isOk;
}
//网站验证登录
function CheckWebLogin()
{
    var isOk = true;
    var name=$$("ctl00_UC_WebTop1_txtUserName");
    var password=$$("ctl00_UC_WebTop1_txtPassword");
    
    if(name.value == "")
    {
        alert("请输入用户名!");
        name.focus();
        isOk=false;
    }
    else if(password.value == "")
    {
        alert("请输入密码!");
        password.focus();
        isOk=false;
    }
    
    return isOk;
}
//软件验证登录
function CheckSoftLogin()
{
    var isOk = true;
    var name=$$("ctl00_UC_SoftTop1_txtUserName");
    var password=$$("ctl00_UC_SoftTop1_txtPassword");
    
    if(name.value == "")
    {
        alert("请输入用户名!");
        name.focus();
        isOk=false;
    }
    else if(password.value == "")
    {
        alert("请输入密码!");
        password.focus();
        isOk=false;
    }
    
    return isOk;
}
function CheckFeedback()
{
    var isOk = true;
    var title = $$("ctl00_formBody_txtTitle");
    var name = $$("ctl00_formBody_txtName");
    var tel = $$("ctl00_formBody_txtTel");
    var content = $$("ctl00_formBody_txtContent");
    
    if(title.value == "")
    {
        alert("请输入标题!");
        title.focus();
        isOk=false;
    }
    else if(name.vale == "")
    {
        alert("请输入姓名!");
        name.focus();
        isOk=false;
    }
    else if(tel.vale == "")
    {
        alert("请输入联系电话!");
        tel.focus();
        isOk=false;
    }
    else if(content.value == "")
    {
        alert("请输入咨询内容!");
        //content.focus();
        isOk=false;
    }
    
    return isOk;
}
//上传资料
function CheckUploadInfo()
{
    var isOk = true;
    var title = $$("ctl00_formBody_txtTitle");
    var path = $$("ctl00_formBody_txtPicPath");
    if(title.value == "")
    {
        alert("请输入标题!");
        title.focus();
        isOk=false;
    }
    else if(path.value == "")
    {
        alert("请上传资料!");
        //path.focus();
        isOk=false;
    }
    return isOk;
}
//上传新闻
function CheckUploadImage()
{
    var isOk = true;
    var titleNes = $$("ctl00_formBody_txtTitleNews");
    var fckContent = $$("ctl00_formBody_fckContent");
    if(titleNes.value == "")
    {
        alert("请输入标题!");
        titleNes.focus();
        isOk=false;
    }
    else if(fckContent.value == "")
    {
        alert("请输入内容!");
        //fckContent.focus();
        isOk=false;
    }
    return isOk;
}
//上传图片
function CheckServer()
{
    var isOk = true;
    var content = $$("ctl00_formBody_txtContent");
    if(content.value == "")
    {
        alert("请输入内容!");
        content.focus();
        isOk=false;
    }
    return isOk;
}
function CheckTGBook()
{
    var isOk = true;
    var name = $$("ctl00_formBody_txtPurchaser");
    var id = $$("txtIdentity");
    var tel = $$("ctl00_formBody_LiteralPhone");
    var chloroplast = $$("txtSelectedChloroplast");
    var address = $$("ctl00_formBody_LiteralAddress");
    var content = $$("ctl00_formBody_fckContent");
    if(name.value == "")
    {
        alert("请输入姓名!");
        title.focus();
        isOk=false;
    }
    else if(id.vale == "")
    {
        alert("请输入身份证!");
        name.focus();
        isOk=false;
    }
    else if(tel.vale == "")
    {
        alert("请输入电话!");
        tel.focus();
        isOk=false;
    }
    else if(chloroplast.value == "")
    {
        alert("请选择所选套型!");
        content.focus();
        isOk=false;
    }
    else if(address.value == "")
    {
        alert("请输入地址!");
        address.focus();
        isOk=false;
    }
    else if(content.value == "")
    {
        alert("请输入违约责任!");
        //content.focus();
        isOk=false;
    }
    
    return isOk;
}
//网站左侧验证登录
function CheckLeftLogin()
{
    var isOk = true;
    var name = $$("ctl00_formBody_UC_LeftLogin1_txtUserName");
    var password = $$("ctl00_formBody_UC_LeftLogin1_txtPassword");
    var code = $$("ctl00_formBody_UC_LeftLogin1_txtCode")
    
    if(name.value == "")
    {
        alert("请输入用户名!");
        name.focus();
        isOk=false;
    }
    else if(password.value == "")
    {
        alert("请输入登录密码!");
        password.focus();
        isOk=false;
    }
    else if(code.value == "")
    {
        alert("请输入验证码!");
        code.focus();
        isOk=false;
    }
    
    return isOk;
}
function CheckTitle()
{
    var isOk = true;
    var title = $$("ctl00_formBody_txtTitle");
    var content = $$("ctl00_formBody_txtContent");
    
    if(title.value == "")
    {
        alert("请输入主题!");
        title.focus();
        isOk = false;
    }
    else if(content.value == "")
    {
        alert("请输入内容!");
        content.focus();
        isOk = false;
    }
    
    return isOk;
}
function ShowTd(index)
{
    var tbls = document.getElementsByName("tbl");
    var tdms = document.getElementsByName("tdm");
    
    for(var i = 0; i<tbls.length; i++)
    {
        tbls[i].style.display = "none";
        tdms[i].style.backgroundColor ="#FEF9E5";
        tdms[i].className = "hhd12";  
        
        if(i == index)
        {
            tbls[i].style.display = "block";
            tdms[i].style.backgroundColor ="#FFE5B5";
            tdms[i].className = "red12c";   
        }
    }
}
function ShowCD(index)
{
    var cds = document.getElementsByName("cd");
    
    for(var i = 0 ; i<cds.length; i++)
    {
        cds[i].style.background = "url(../images/Soft/dtcebt.jpg)";
    
        if(i == index)
        {
            cds[i].style.background = "url(../images/Soft/dtcebtt.jpg)";
        }
    }
}

抱歉!评论已关闭.