本人ajax留言板的源程序 不错的应用js

汤晓伟nice

汤晓伟nice

2016-02-19 11:28

下面图老师小编要向大家介绍下本人ajax留言板的源程序 不错的应用js,看起来复杂实则是简单的,掌握好技巧就OK,喜欢就赶紧收藏起来吧!
代码如下:

// JavaScript Document
function $(id)
{
    return document.getElementById(id);    
}
function echo(obj,html)
{
    $(obj).innerHTML=html;
}
function fopen(obj)
{
    $(obj).style.display="";
}
function fclose(obj)
{
    $(obj).style.display="none";
}
function lTrim(str)
{
  if (str.charAt(0) == " ")
  {
    //如果字串左边第一个字符为空格
    str = str.slice(1);//将空格从字串中去掉
    //这一句也可改成 str = str.substring(1, str.length);
    str = lTrim(str);    //递归调用
  }
  return str;
}

//去掉字串右边的空格
function rTrim(str)
{
  var iLength;

  iLength = str.length;
  if (str.charAt(iLength - 1) == " ")
  {
    //如果字串右边第一个字符为空格
    str = str.slice(0, iLength - 1);//将空格从字串中去掉
    //这一句也可改成 str = str.substring(0, iLength - 1);
    str = rTrim(str);    //递归调用
  }
  return str;
}

//去掉字串两边的空格
function trim(str)
{
  return lTrim(rTrim(str));
}
function sck(s)
{
    return s.replace(/n/g,"[br]");
    //s=s.replace(chr(13)&chr(23),"br /");    
    //return s;
}
function f(obj)
{
    return trim(eval("document.forms[0]."+obj+".value"));
    //return trim($(obj).value);
}
function setf(obj)
{
    return eval("document.forms[0]."+obj+".focus();");
}
function show(obj)
{
    var s=$(obj).style;
    s.display=s.display=="none" ? "" : "none";
}
function echo(obj,html)
{
        $(obj).innerHTML=html;
}
function createxmlhttp()
{
    var xmlhttp=false;
    try    {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     } 
    catch (e) {
          try {
               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } 
        catch (e) {
               xmlhttp = false;
         }
     }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
          xmlhttp = new XMLHttpRequest();
                if (xmlhttp.overrideMimeType) {//设置MiME类别
            xmlhttp.overrideMimeType('text/xml');
        }
    }    

    return xmlhttp;    
}
function getnum(url,obj)
{        
        //var b="";
        var xmlhttp=createxmlhttp();
        if(!xmlhttp)
        {
            alert("你的浏览器不支持XMLHTTP!!");
            return;
        }
        xmlhttp.onreadystatechange=requestdata;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
        function requestdata(){
        if(xmlhttp.readyState==4)
        {
            if(xmlhttp.status==200)
                {
                $(obj).value=xmlhttp.responseText;    
                }
        }
        }
}
function getdata(url,obj1,obj2)
{

        var xmlhttp=createxmlhttp();
        if(!xmlhttp)
        {
            alert("你的浏览器不支持XMLHTTP!!");
            return;
        }
        xmlhttp.onreadystatechange=requestdata;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
        function requestdata()
        {

                fopen(obj1);
                echo(obj1,"正在加载数据,请稍等......");
                if(xmlhttp.readyState==4)
                {
                    if(xmlhttp.status==200)
                    {
                        if(obj1!=obj2){fclose(obj1);};
                        echo(obj2,xmlhttp.responseText);

                    }
                }

        }
}
function postdata(url,obj,data)
{
        var xmlhttp=createxmlhttp();
        if(!xmlhttp)
        {
            alert("你的浏览器不支持XMLHTTP!!");
            return;
        }
        xmlhttp.open("POST", url, true);
        xmlhttp.onreadystatechange=requestdata;
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xmlhttp.send(data);
        function requestdata()
        {
            fopen(obj);
            echo(obj,"正在提交数据,请稍等......");
            //alert(xmlhttp.readyState);
            if(xmlhttp.readyState==4)
            {
                //alert(xmlhttp.status);
                if(xmlhttp.status==200)
                {
                    echo(obj,xmlhttp.responseText);
                }
            }
        }
}
function checkform(obj,id)
{
    if(f("user")=="")
    {
        alert("请留下您的大名!!");
        setf("user");
        return false;
    }
    if(f("user").length10 && f("user")2 )
    {
        alert("姓名长度只能在2-10位之间!!");
    }
    if(f("title")=="")
    {
        alert("请填写留言标题!!");
        setf("title");
        return false;
    }
    if(f("title").length50)
    {
        alert("对不起标题太长了!!");
        setf("title");
        return false;
    }
    if(f("content")=="")
    {
        alert("留言内容不能为空!!");
        setf("content");
        return false;
    }
    data="user="+escape(f("user"))+"&title="+escape(f("title"))+"&content="+escape(document.forms[0].content.value)+"&reply="+escape(f("reply"));
    //alert(data);
 // data="content="+escape(sck(f("content")));
    if(obj=="add")
    {
        //alert(obj);
        postdata("file.asp?action=addsave","contentdata",data);
    }else if(obj=="reply")
    {
        postdata("file.asp?action=replysave","contentadmin"+id,data);
    }
    return true;
}
function adminlogin()
{
    if($("adminuser").value=="")    
    {
        alert("管理帐号不能为空!");
        $("adminuser").focus();
        return false;
    }
    if($("adminpwd").value=="")
    {
        alert("管理密码不能为空!");
        $("adminpwd").focus();
        return false;
    }
    data="adminuser="+escape($("adminuser").value)+"&adminpwd="+escape($("adminpwd").value);
    postdata("file.asp?action=checkadmin","loginlist",data);
    return true;
}
function adreset()
{
    $("adminuser").value="";
    $("adminpwd").value="";
}
function linktool()
{
    if($("linktool").innerHTML=="自助链接")
    {
                $("linktool").innerHTML="友情链接";
            getdata("list.asp?action=addlink","linklist","linklist");

    }else
    {

            $("linktool").innerHTML="自助链接";
            getdata("list.asp?action=linklist","linklist","linklist");
    }
}
function addlink()
{
    if($("home").value=="")    
    {
        alert("网站名称不能为空");
        $("home").focus();
        return false;
    }
    if($("url").value=="")
    {
        alert("网站地址不能为空!");
        $("url").focus();
        return false;
    }
    data="home="+escape($("home").value)+"&url="+escape($("url").value);
    postdata("list.asp?action=linksave","linklist",data);
    return true;
}
function linkreset()
{
    $("home").value="";
    $("url").value="";
}
function updatepwd()
{
    if(f("user")=="")
    {
        alert("请输入管理帐号!");
        setf("user");
        return false;
    }
    if(f("npwd")=="")
    {
        alert("请输入管理密码!");
        setf("npwd");
        return false;
    }
    if(f("npwd")!=f("npwd1"))
    {
        alert("新密码和确认密码不一样!!");
        setf("npwd");
        return false;
    }
    data="user="+escape(f("user"))+"&pwd="+escape(f("npwd"));
    postdata("list.asp?action=savepwd","contentdata",data);
    return true;
}
function updateinfo()
{
    if(f("gonggao")=="")
    {
        alert("公告内容不能为空!");
        setf("gonggao");
        return false;
    }
    if(f("foot")=="")
    {
        alert("版权信息不能为空!");
        setf("foot");
        return false;
    }
    data="news="+escape(document.forms[0].gonggao.value)+"&foot="+escape(document.forms[0].foot.value);
    postdata("list.asp?action=infosave","contentdata",data);
    return true;
}

打包文件下载
展开更多 50%)
分享

猜你喜欢

本人ajax留言板的源程序 不错的应用js

Web开发
本人ajax留言板的源程序 不错的应用js

asp简单的ajax留言板

Web开发
asp简单的ajax留言板

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

asp简单的ajax留言板(采用三层模式)

电脑网络
asp简单的ajax留言板(采用三层模式)

ajax不错的应用

Web开发
ajax不错的应用

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

开发基于XML的留言板

Web开发
开发基于XML的留言板

留言板翻页的实现详解

PHP
留言板翻页的实现详解

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

xcode 4 制作静态库图文详解

xcode 4 制作静态库图文详解

Win10如何去除桌面图标左上角的小方框

Win10如何去除桌面图标左上角的小方框
下拉加载更多内容 ↓