载入中

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/OnlyRu/article/details/80061697
网页加载过程中提示“载入中…”,特别是使用动画效果,可以一个“等待”的温馨提示,用户体验很不错。


先说最简单的第一种,原理就是,在网页载入时在页面最中间打入一个层上面显示,"网页正在载入中...."当网页下载完毕,,用js关闭这个层......。


先在首页HTML最上面...任意位置都行..加入


<DIV id=loading style="position:absolute; left:423px; top:261px; width:227px; height:20px; z-index:1">
正在载入中,请稍等.....</div>
<SCRIPT language=JavaScript>
function closeDiv()
{
document.getElementById('loading').style.visibility='hidden';
}
</SCRIPT>


然后在HTML末尾加入
 <SCRIPT LANGUAGE="javascript">
<!--
closeDiv()
//-->


这种简单明了,不过效果可能不会很精确。


第二种以假乱真的


 就是利用一个百分比来连续加入一组“||”字符串,然后达到 100% 之后执行一次 self.location.href 跳转。


下面是实现代码:


<html>
<head>
<title>正在载入...</title>
<meta http-equiv="Content-Type" c>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0">
<table border=0 cellpadding=0 cellspacing=0 width="100%" height="100%">
<tr>
<form name=loading>
<td align=center>
<p><font color=gray>正在载入首页,请稍候.......</font></p>
<p>
<input type=text name=chart size=46 style="font-family:Arial;
font-weight:bolder; color:gray;
background-color:white; padding:0px; border-style:none;">
<br>
<input type=text name=percent size=46 style="font-family:Arial;
color:gray; text-align:center;
border-width:medium; border-style:none;">
<script>var bar = 0
var line = "||"
var amount ="||"
count()
function count(){
bar= bar+2
amount =amount + line
document.loading.chart.value=amount
document.loading.percent.value=bar+"%"
if (bar<99)
{setTimeout("count()",100);}
else
{window.location = "http://www.XXXX.com/";}
}
</script>
</p>
</td>
</form>
</tr>
</table>
</body>
</html>


但是这种办法跳转过去再次读取页面而这个效果也就起不到任何预载入的功能,只能说是以假乱真罢了。


第三种:利用DOM模型的document.all 来 document.layers这两个对象来做判断页面是否加载完毕从而实现层的现实和隐藏。顺便说明下document.all 和 document.layers。


document.all是IE浏览器所具有的对象集合,一般用if(document.all)来判断是否是IE浏览器,这个集合代表document对象下所有元素;
document.layers是网景Netscape浏览器所具有的对象集合,这个集合代表document对象下所有的layer(层)。


下面是实现代码:


<html>
<head>
<title>Loading.....</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
<!--
var url = 'http://www.XXXX.com';
//-->
</script>
</head>
<body scroll="no" bgcolor="#FFFFFF" onLoad="location.href = url">
<div align="center">
<br><br><br><br><br><br><br>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#FF6600">正在载入XXXX....</font>
</p>
<p>
<script>
<!--
if (document.layers)
     document.write('<Layer src="' + url + ' " VISIBILITY="hide"> </Layer>');
     else if (document.all || document.getElementById)
      document.write('<iframe src="' + url + '" style="visibility: hidden;"></iframe>');
else location.href = url;
//-->
</script>
</p>
</div>
</body>
</html>


第四种是利用window.onload 是在页面完全读取完毕才执行的特性。


首先在我们在要使用载入条的 HTML 页面设计一个 ID 为 LoadingBar 的层(此层的样式可以随便设置,还可以加入图片在其中。总之就是只要 ID 符合条件,其它都可以随便


javascipt代码:


function initPage()   
{   
    var objLoading = document.getElementById("LoadingBar");   
    if (objLoading != null)   
    {   
        objLoading.style.display = "none";   
    }   
}  
html代码:<div id="LoadingBar">正在载入,请稍候……</div> 


这个语句最好是放在页的最前端,也就是紧跟 <body> 标签的下面一行,这样才能确保在读页面的时候最先显示这一层。最后,要在头部加上一段 JavaScript:window.onload = initPage();


initPage 其实就是最先我不说明用途的那个 initPage() 函数,其实就是关闭 LoadingBar 层的一个过程。


 最后一种又简单,也好理解。






用JS获取地址栏参数的方法(超级简单)
方法一:采用正则表达式获取地址栏参数:( 强烈推荐,既实用又方便!)


function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}
 
// 调用方法
alert(GetQueryString("参数名1"));
alert(GetQueryString("参数名2"));
alert(GetQueryString("参数名3"));
下面举一个例子:


若地址栏URL为:abc.html?id=123&url=http://www.maidq.com


那么,但你用上面的方法去调用:alert(GetQueryString("url"));


则会弹出一个对话框:内容就是 http://www.maidq.com


如果用:alert(GetQueryString("id"));那么弹出的内容就是 123 啦;


当然如果你没有传参数的话,比如你的地址是 abc.html 后面没有参数,那强行输出调用结果有的时候会报错:


所以我们要加一个判断 ,判断我们请求的参数是否为空,首先把值赋给一个变量:


var myurl=GetQueryString("url");
if(myurl !=null && myurl.toString().length>1)
{
   alert(GetQueryString("url"));
}
这样就不会报错了!


方法二:传统方法


<script type="text/javascript">
function UrlSearch() 
{
   var name,value; 
   var str=location.href; //取得整个地址栏
   var num=str.indexOf("?") 
   str=str.substr(num+1); //取得所有参数   stringvar.substr(start [, length ]


   var arr=str.split("&"); //各个参数放到数组里
   for(var i=0;i < arr.length;i++){ 
    num=arr[i].indexOf("="); 
    if(num>0){ 
     name=arr[i].substring(0,num);
     value=arr[i].substr(num+1);
     this[name]=value;
     } 
    } 

var Request=new UrlSearch(); //实例化
alert(Request.id);
</script>


比如说把这个代码存为1.html


那么我要访问1.html?id=test


这个时候就取到test的值了




在html里调用
<script type="text/javascript">
var a="http://baidu.com";
</script>
</head>
<body>
<a id="a1" href="">sadfsdfas</a>
<script>
var a1=document.getElementById("a1");
a1.href=a;
</script>


<script type="text/javascript"> 
var a="http://xxx.com/gg.htm?cctv"; 
var s=a.indexOf("?"); 
var t=a.substring(s+1);// t就是?后面的东西了 


</script>


stringvar.substr(start [, length ]


返回一个从指定位置开始的指定长度的子字符串。


stringvar


必选项。要提取子字符串的字符串文字或 String 对象。


start


必选项。所需的子字符串的起始位置。字符串中的第一个字符的索引为 0。


length


可选项。在返回的子字符串中应包括的字符个数。


如果 length 为 0 或负数,将返回一个空字符串。如果没有指定该参数,则子字符串将延续到 stringvar 的最后。


下面列举出一些相关的参数:


str.toLowerCase()   转换成小写  
str.toUpperCase()   字符串全部转换成大写


URL即:统一资源定位符 (Uniform Resource Locator, URL) 
完整的URL由这几个部分构成:
scheme://host:port/path?query#fragment 
scheme:通信协议
常用的http,ftp,maito等


host:主机
服务器(计算机)域名系统 (DNS) 主机名或 IP 地址。


port:端口号
整数,可选,省略时使用方案的默认端口,如http的默认端口为80。


path:路径
由零或多个"/"符号隔开的字符串,一般用来表示主机上的一个目录或文件地址。


query:查询
可选,用于给动态网页(如使用CGI、ISAPI、PHP/JSP/ASP/ASP.NET等技术制作的网页)传递参数,可有多个参数,用"&"符号隔开,每个参数的名和值用"="符号隔开。


fragment:信息片断
字符串,用于指定网络资源中的片断。例如一个网页中有多个名词解释,可使用fragment直接定位到某一名词解释。(也称为锚点.)


对于这样一个URL


http://www.maidq.com/index.html?ver=1.0&id=6#imhere


我们可以用javascript获得其中的各个部分
1, window.location.href
整个URl字符串(在浏览器中就是完整的地址栏)
本例返回值: http://www.maidq.com/index.html?ver=1.0&id=6#imhere


2,window.location.protocol
URL 的协议部分
本例返回值:http:


3,window.location.host
URL 的主机部分
本例返回值:www.maidq.com


4,window.location.port
URL 的端口部分
如果采用默认的80端口(update:即使添加了:80),那么返回值并不是默认的80而是空字符
本例返回值:""


5,window.location.pathname
URL 的路径部分(就是文件地址)
本例返回值:/fisker/post/0703/window.location.html


6,window.location.search
查询(参数)部分
除了给动态语言赋值以外,我们同样可以给静态页面,并使用javascript来获得相信应的参数值
本例返回值:?ver=1.0&id=6


7,window.location.hash
锚点
本例返回值:#imhere








protected bool isNumberic(string message,out int result)
{
        System.Text.RegularExpressions.Regex rex=
        new System.Text.RegularExpressions.Regex(@"^\d+$");
        result = -1;
        if (rex.IsMatch(message))
        {
            result = int.Parse(message);
            return true;
        }
        else
            return false;
}




public static DataTable ToDataTable<T>(this IEnumerable<T> list)  
    {  
  
        //创建属性的集合    
        List<PropertyInfo> pList = new List<PropertyInfo>();  
        //获得反射的入口    
  
        Type type = typeof(T);  
        DataTable dt = new DataTable();  
        //把所有的public属性加入到集合 并添加DataTable的列    
        Array.ForEach<PropertyInfo>(type.GetProperties(), p => { pList.Add(p); dt.Columns.Add(p.Name, p.PropertyType); });  
        foreach (var item in list)  
        {  
            //创建一个DataRow实例    
            DataRow row = dt.NewRow();  
            //给row 赋值    
            pList.ForEach(p => row[p.Name] = p.GetValue(item, null));  
            //加入到DataTable    
            dt.Rows.Add(row);  
        }  
        return dt;  
    }  




 //表中有数据或无数据时使用,可排除DATASET不支持System.Nullable错误
    public static DataTable ConvertToDataSet<T>(IList<T> list)
        {
            if (list == null || list.Count <= 0)
            //return null;
            {
                DataTable result = new DataTable();
                object temp;
                if (list.Count > 0)
                {
                    PropertyInfo[] propertys = list[0].GetType().GetProperties();
                    foreach (PropertyInfo pi in propertys)
                    {
                        //if (!(pi.Name.GetType() is System.Nullable))
                        //if (pi!=null)
                        {
                            //pi = (PropertyInfo)temp;  
                            result.Columns.Add(pi.Name, pi.PropertyType);
                        }
                    }
                    for (int i = 0; i < list.Count; i++)
                    {
                        ArrayList tempList = new ArrayList();
                        foreach (PropertyInfo pi in propertys)
                        {
                            object obj = pi.GetValue(list[i], null);
                            tempList.Add(obj);
                        }
                        object[] array = tempList.ToArray();
                        result.LoadDataRow(array, true);
                    }
                }
                return result;
            }
            else
            {
                DataSet ds = new DataSet();
                DataTable dt = new DataTable(typeof(T).Name);
                DataColumn column;
                DataRow row;
                System.Reflection.PropertyInfo[] myPropertyInfo =
                    typeof(T).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
                foreach (T t in list)
                {
                    if (t == null) continue;
                    row = dt.NewRow();
                    for (int i = 0, j = myPropertyInfo.Length; i < j; i++)
                    {
                        System.Reflection.PropertyInfo pi = myPropertyInfo[i];
                        String name = pi.Name;
                        if (dt.Columns[name] == null)
                        {
                            if (pi.PropertyType.UnderlyingSystemType.ToString() == "System.Nullable`1[System.Int32]")
                            {
                                column = new DataColumn(name, typeof(Int32));
                                dt.Columns.Add(column);
                                //row[name] = pi.GetValue(t, new object[] {i});//PropertyInfo.GetValue(object,object[])
                                if (pi.GetValue(t, null) != null)
                                    row[name] = pi.GetValue(t, null);
                                else
                                    row[name] = System.DBNull.Value;
                            }
                            else
                            {
                                column = new DataColumn(name, pi.PropertyType);
                                dt.Columns.Add(column);
                                row[name] = pi.GetValue(t, null);
                            }
                        }
                    }
                    dt.Rows.Add(row);
                }
                ds.Tables.Add(dt);
                return ds.Tables[0];
            }
        }
}




<form method="post">
<table class="dv-table" style="width:100%;background:#fafafa;padding:5px;margin-top:5px;">
<tr>
<td>First Name</td>
<td><input name="firstname" class="easyui-validatebox" required="true"></input></td>
<td>Last Name</td>
<td><input name="lastname" class="easyui-validatebox" required="true"></input></td>
</tr>
<tr>
<td>Phone</td>
<td><input name="phone"></input></td>
<td>Email</td>
<td><input name="email" class="easyui-validatebox" validType="email"></input></td>
</tr>
</table>
<div style="padding:5px 0;text-align:right;padding-right:30px">
<a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="saveItem(<?php echo $_REQUEST['index'];?>)">Save</a>
<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" plain="true" onclick="cancelItem(<?php echo $_REQUEST['index'];?>)">Cancel</a>
</div>
</form>




return '<table><tr>' +
'<td rowspan=2 style="border:0"><img src="images/' + rowData.itemid + '.png" style="height:50px;"></td>' +
'<td style="border:0">' +
'<p>Attribute: ' + rowData.attr1 + '</p>' +
'<p>Status: ' + rowData.status + '</p>' +
'</td>' +
'</tr></table>';

猜你喜欢

转载自blog.csdn.net/OnlyRu/article/details/80061697