国产亚洲午夜高清国产拍精品,国产一区二区免费在线,偷拍与自拍一区http://www.aygfsteel.com/lyjjq/category/20795.html我喜歡java新東西zh-cnFri, 20 Sep 2013 00:17:05 GMTFri, 20 Sep 2013 00:17:05 GMT60JS刷新頁(yè)面http://www.aygfsteel.com/lyjjq/articles/404228.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Wed, 18 Sep 2013 15:06:00 GMThttp://www.aygfsteel.com/lyjjq/articles/404228.htmlhttp://www.aygfsteel.com/lyjjq/comments/404228.htmlhttp://www.aygfsteel.com/lyjjq/articles/404228.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/404228.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/404228.htmlreload 方法,該方法強(qiáng)迫瀏覽器刷新當(dāng)前頁(yè)面。
語(yǔ)法:location.reload([bForceGet])                                                                                                                           參數(shù): bForceGet, 可選參數(shù), 默認(rèn)為 false,從客戶端緩存里取當(dāng)前頁(yè)。true, 則以 GET 方式,從服務(wù)端取最新的頁(yè)面, 相當(dāng)于客戶端點(diǎn)擊 F5("刷新")

replace 方法,該方法通過(guò)指定URL替換當(dāng)前緩存在歷史里(客戶端)的項(xiàng)目,因此當(dāng)使用replace方法之后,你不能通過(guò)“前進(jìn)”和“后退”來(lái)訪問(wèn)已經(jīng)被替換的URL。
語(yǔ)法: location.replace(URL)   

在實(shí)際應(yīng)用的時(shí)候,重新刷新頁(yè)面的時(shí)候,我們通常使用: location.reload() 或者是 history.go(0) 來(lái)做。因?yàn)檫@種做法就像是客戶端點(diǎn)F5刷新頁(yè)面,所以頁(yè)面的method="post"的時(shí)候,會(huì)出現(xiàn)"網(wǎng)頁(yè)過(guò)期"的提示。那是因?yàn)镾ession的安全保護(hù)機(jī)制。可以想到: 當(dāng)調(diào)用 location.reload() 方法的時(shí)候, aspx頁(yè)面此時(shí)在服務(wù)端內(nèi)存里已經(jīng)存在, 因此必定是 IsPostback 的。如果有這種應(yīng)用: 我們需要重新加載該頁(yè)面,也就是說(shuō)我們期望頁(yè)面能夠在服務(wù)端重新被創(chuàng)建, 我們期望是 Not IsPostback 的。這里,location.replace() 就可以完成此任務(wù)。被replace的頁(yè)面每次都在服務(wù)端重新生成。

你可以這么寫: location.replace(location.href);

 


返回并刷新頁(yè)面:

location.replace(document.referrer);

document.referrer //前一個(gè)頁(yè)面的URL

不要用 history.go(-1),或 history.back();來(lái)返回并刷新頁(yè)面,這兩種方法不會(huì)刷新頁(yè)面。

附:
Javascript刷新頁(yè)面的幾種方法:
1    history.go(0)
2    location.reload()
3    location=location
4    location.assign(location)
5    document.execCommand('Refresh')
6    window.navigate(location)
7    location.replace(location)
8    document.URL=location.href

 


自動(dòng)刷新頁(yè)面的方法:
1.頁(yè)面自動(dòng)刷新:把如下代碼加入<head>區(qū)域中
<meta http-equiv="refresh" content="20">
其中20指每隔20秒刷新一次頁(yè)面.

2.頁(yè)面自動(dòng)跳轉(zhuǎn):把如下代碼加入<head>區(qū)域中
<meta http-equiv="refresh" content="20;url=http://www.wyxg.com">
其中20指隔20秒后跳轉(zhuǎn)到http://www.wyxg.com頁(yè)面

3.頁(yè)面自動(dòng)刷新js版
<script language="JavaScript">
function myrefresh()
{
       window.location.reload();
}
setTimeout('myrefresh()',1000); //指定1秒刷新一次
</script>

 

JS刷新框架的腳本語(yǔ)句

//如何刷新包含該框架的頁(yè)面用  
<script language=JavaScript>
   parent.location.reload();
</script>  


//子窗口刷新父窗口
<script language=JavaScript>
    self.opener.location.reload();
</script>
( 或 <a href="javascript:opener.location.reload()">刷新</a>   )

//如何刷新另一個(gè)框架的頁(yè)面用  
<script language=JavaScript>
   parent.另一FrameID.location.reload();
</script>

如果想關(guān)閉窗口時(shí)刷新或者想開(kāi)窗時(shí)刷新的話,在<body>中調(diào)用以下語(yǔ)句即可。

<body onload="opener.location.reload()"> 開(kāi)窗時(shí)刷新
<body onUnload="opener.location.reload()"> 關(guān)閉時(shí)刷新

<script language="javascript">
window.opener.document.location.reload()
</script>
 



強(qiáng)強(qiáng) 2013-09-18 23:06 發(fā)表評(píng)論
]]>
Javascript_表單驗(yàn)證大全(收集)http://www.aygfsteel.com/lyjjq/articles/400001.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Fri, 31 May 2013 00:00:00 GMThttp://www.aygfsteel.com/lyjjq/articles/400001.htmlhttp://www.aygfsteel.com/lyjjq/comments/400001.htmlhttp://www.aygfsteel.com/lyjjq/articles/400001.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/400001.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/400001.html5、身份證驗(yàn)證:包括15位和18位。
   function idNumber(s)//身份證驗(yàn)證
           {
             regu1=/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;//15wei
             regu2=/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/;//18wei
             re1=new RegExp(regu1);
             re2=new RegExp(regu2);
            
             if(!(re1.test(s)||re2.test(s)))
             {
                   document.getElementById ("idCardInf").innerHTML="格式不對(duì)!";
                   document.getElementById ("idCardInf").style.color="red";
               
             }
             else
             {
                  document.getElementById ("idCardInf").innerHTML="通過(guò)!";
                  document.getElementById ("idCardInf").style.color="green";
                  document.getElementById ("idCardCheck").innerHTML="";
             }
            
//             alert("請(qǐng)正確填寫18位或15位身份證號(hào)碼");
           }
6、手機(jī)號(hào)碼驗(yàn)證:13和15開(kāi)頭的號(hào)碼。
   function isMobileNO(s)//手機(jī)驗(yàn)證
           {
             var a = /^((\(\d{3}\))|(\d{3}\-))?13\d{9}|15\d{9}$/ ;
           if( !s.match(a) )
           {
               document.getElementById ("mobileNOInf").innerHTML="格式不對(duì)!";
               document.getElementById ("mobileNOInf").style.color="red";
//                   alert("手機(jī)號(hào)碼格式不對(duì)");
           }
           else
           {
                  document.getElementById ("mobileNOInf").innerHTML="通過(guò)!";
                  document.getElementById ("mobileNOInf").style.color="green";
                  document.getElementById ("mobileNOCheck").innerHTML="";
           }
          
           }
7、各表單域提示信息,獲得焦點(diǎn)驗(yàn)證。
      function displayInform(s)//注冊(cè)信息規(guī)則提示信息(獲得焦點(diǎn)驗(yàn)證)
           {
             if(s=="user")
             document.getElementById ("userIDCheck").innerHTML="(用戶名由4-16個(gè)數(shù)字或字母組成)";
             if(s=="password")
             document.getElementById ("passwordCheck").innerHTML="(密碼由6-16個(gè)數(shù)字、字母、下劃線組成,首字母必須是字母,不區(qū)分大小寫)";
             if(s=="passwordC")
             document.getElementById ("confirmCheck").innerHTML="(兩次密碼輸入必須一致)";
             if(s=="idCard")
             document.getElementById ("idCardCheck").innerHTML="(請(qǐng)輸入正確的號(hào)碼,以便你更容易找回密碼)";
             if(s=="mobileNO")
             document.getElementById ("mobileNOCheck").innerHTML="(請(qǐng)輸入正確的號(hào)碼,以便你更快找回密碼)";
             if(s=="email")
             document.getElementById ("emailCheck").innerHTML="(請(qǐng)輸入正確的郵箱地址,以便你更容易找回密碼)";
            
           }
8、表單提交驗(yàn)證:先對(duì)必填項(xiàng)進(jìn)行非空驗(yàn)證,再進(jìn)行匹配驗(yàn)證。
    function submitValidator() //提交驗(yàn)證
          {
            if(document.getElementById("control").style.display=="inline")
            {
                if((document.getElementById ("user").value=="")||(document.getElementById("password").value=="")||(document.getElementById("passwordC").value=="")||(document.getElementById("answer").value=="")||(document.getElementById("question").value==""))
               {
                  alert("必填項(xiàng)不能為空!");
                   return false;
                }
                else
               {
                  if((document.getElementById ("user").value).match(/^[0-9a-zA-Z]{4,16}$/)&&(document.getElementById("password").value).match(/^[a-zA-Z][0-9a-zA-Z_]{5,15}$/)&&
                  (document.getElementById ("password").value.toLowerCase()==document.getElementById ("passwordC").value.toLowerCase()))
                  {return true;}
                  else
                  {alert("輸入格式不對(duì)");return false;}
                }
            }
            else
            {
               if((document.getElementById ("user").value=="")||(document.getElementById("password").value=="")||(document.getElementById("passwordC").value=="")||(document.getElementById("answer").value==""))
               {
                  alert("必填項(xiàng)不能為空!");
                   return false;
                }
                else
               {
                  if((document.getElementById ("user").value).match(/^[0-9a-zA-Z]{4,16}$/)&&(document.getElementById("password").value).match(/^[a-zA-Z][0-9a-zA-Z_]{5,15}$/)&&
                  (document.getElementById ("password").value.toLowerCase()==document.getElementById ("passwordC").value.toLowerCase()))
                  {return true;}
                  else
                  {alert("輸入格式不對(duì)");return false;}
                }
            }
本文來(lái)自CSDN博客,轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://blog.csdn.net/diershi/archive/2009/04/16/4084981.aspx
JS表單驗(yàn)證
<script language="JavaScript">
/*
*--------------- 客戶端表單通用驗(yàn)證CheckForm(oForm) -----------------
* 功能:通用驗(yàn)證所有的表單元素.
* 使用:
*    <form name="form1" onsubmit="return CheckForm(this)">
*    <input type="text" name="id" check="^\S+$" warning="id不能為空,且不能含有空格"/>
*    <input type="submit"/>
*    </form>
* author:wanghr100(灰豆寶寶.net)
* email:wanghr100@126.com
* update:19:28 2004-8-23
* 注意:寫正則表達(dá)式時(shí)一定要小心.不要讓"有心人"有空子鉆.
* 已實(shí)現(xiàn)功能:
* 對(duì)text,password,hidden,file,textarea,select,radio,checkbox進(jìn)行合法性驗(yàn)證
* 待實(shí)現(xiàn)功能:把正則表式寫成個(gè)庫(kù).
*--------------- 客戶端表單通用驗(yàn)證CheckForm(oForm) -----------------
*/
////////////////////////////////////////////////////////////////////////////////
//主函數(shù)
function CheckForm(oForm)
{
    var els = oForm.elements;
    //遍歷所有表元素
    for(var i=0;i<els .length;i++)
    {
        //是否需要驗(yàn)證
        if(els.check)
        {
            //取得驗(yàn)證的正則字符串
            var sReg = els.check;
            //取得表單的值,用通用取值函數(shù)
            var sVal = GetValue(els);
            //字符串->正則表達(dá)式,不區(qū)分大小寫
            var reg = new RegExp(sReg,"i");
            if(!reg.test(sVal))
            {
                //驗(yàn)證不通過(guò),彈出提示warning
                alert(els.warning);
                //該表單元素取得焦點(diǎn),用通用返回函數(shù)
                GoBack(els)  
                return false;
            }
        }
    }
}
//通用取值函數(shù)分三類進(jìn)行取值
//文本輸入框,直接取值el.value
//單多選,遍歷所有選項(xiàng)取得被選中的個(gè)數(shù)返回結(jié)果"00"表示選中兩個(gè)
//單多下拉菜單,遍歷所有選項(xiàng)取得被選中的個(gè)數(shù)返回結(jié)果"0"表示選中一個(gè)
function GetValue(el)
{
    //取得表單元素的類型
    var sType = el.type;
    switch(sType)
    {
        case "text":
        case "hidden":
        case "password":
        case "file":
        case "textarea": return el.value;
        case "checkbox":
        case "radio": return GetValueChoose(el);
        case "select-one":
        case "select-multiple": return GetValueSel(el);
    }
    //取得radio,checkbox的選中數(shù),用"0"來(lái)表示選中的個(gè)數(shù),我們寫正則的時(shí)候就可以通過(guò)0{1,}來(lái)表示選中個(gè)數(shù)
    function GetValueChoose(el)
    {
        var sValue = "";
        //取得第一個(gè)元素的name,搜索這個(gè)元素組
        var tmpels = document.getElementsByName(el.name);
        for(var i=0;i<tmpels .length;i++)
        {
            if(tmpels.checked)
            {
                sValue += "0";
            }
        }
        return sValue;
    }
    //取得select的選中數(shù),用"0"來(lái)表示選中的個(gè)數(shù),我們寫正則的時(shí)候就可以通過(guò)0{1,}來(lái)表示選中個(gè)數(shù)
    function GetValueSel(el)
    {
        var sValue = "";
        for(var i=0;i<el.options.length;i++)
        {
            //單選下拉框提示選項(xiàng)設(shè)置為value=""
            if(el.options.selected && el.options.value!="")
            {
                sValue += "0";
            }
        }
        return sValue;
    }
}
//通用返回函數(shù),驗(yàn)證沒(méi)通過(guò)返回的效果.分三類進(jìn)行取值
//文本輸入框,光標(biāo)定位在文本輸入框的末尾
//單多選,第一選項(xiàng)取得焦點(diǎn)
//單多下拉菜單,取得焦點(diǎn)
function GoBack(el)
{
    //取得表單元素的類型
    var sType = el.type;
    switch(sType)
    {
        case "text":
        case "hidden":
        case "password":
        case "file":
        case "textarea": el.focus();var rng = el.createTextRange(); rng.collapse(false); rng.select();
        case "checkbox":
        case "radio": var els = document.getElementsByName(el.name);els[0].focus();
        case "select-one":
        case "select-multiple":el.focus();
    }
}
</script>
通用表單函數(shù)測(cè)試:
<form name="form1" onsubmit="return CheckForm(this)">
test:<input type="text" name="test"/>不驗(yàn)證<br />
賬號(hào):<input type="text" check="^\S+$" warning="賬號(hào)不能為空,且不能含有空格" name="id"/>不能為空<br />
密碼:<input type="password" check="\S{6,}" warning="密碼六位以上" name="id"/>六位以上<br />
電話:<input type="text" check="^\d+$" warning="電話號(hào)碼含有非法字符" name="number" value=""/><br />
相片上傳:<input type="file" check="(.*)(\.jpg|\.bmp)$" warning="相片應(yīng)該為JPG,BMP格式的" name="pic" value="1"/><br />
出生日期:<input type="text" check="^\d{4}\-\d{1,2}-\d{1,2}$" warning="日期格式2004-08-10" name="dt" value=""/>日期格式2004-08-10<br />
省份:
<select name="sel" check="^0$" warning="請(qǐng)選擇所在省份">
<option value="">請(qǐng)選擇
</option><option value="1">福建省
</option><option value="2">湖北省
</option></select>
<br />
選擇你喜歡的運(yùn)動(dòng):<br />
游泳<input type="checkbox" name="c" check="^0{2,}$" warning="請(qǐng)選擇2項(xiàng)或以上"/>
籃球<input type="checkbox" name="c"/>
足球<input type="checkbox" name="c"/>
排球<input type="checkbox" name="c"/>
<br />
你的學(xué)歷:
大學(xué)<input type="radio" name="r" check="^0$" warning="請(qǐng)選擇一項(xiàng)學(xué)歷"/>
中學(xué)<input type="radio" name="r"/>
小學(xué)<input type="radio" name="r"/>
<br />
個(gè)人介紹:
<textarea name="txts" check="^[\s|\S]{20,}$" warning="個(gè)人介紹不能為空,且不少于20字"></textarea>20個(gè)字以上
<input type="submit"/>
</form>
---------------------------------------------
Javascript表單編程
    對(duì)form元素進(jìn)行腳本編寫
      獲取表單的引用
        var oForm = document.forms[0]; //得到第一個(gè)表單
        var oOtherForm = document.forms["formz"] //得到名為formz的表單
    
      訪問(wèn)表單字段
        var oTextbox1 = oForm.textbox1; //得到名為"textbox"的字段
        var oTextbox1 = oForm["text box 1"]    //得到名為"text box 1"的字段
      表單字段共性
        var oField 1 = oForm.elements[0];
        oField1.focus(); //設(shè)置焦點(diǎn)到第二個(gè)字段
        獲得焦點(diǎn):document.forms[0].name1.focus();
      表單提交
        使用圖片進(jìn)行提交
          <input type="image" src="submit.gif" />
        使用submit進(jìn)行提交
          <input type="submit" value="submit" />
      表單重置
        <input type="button" value="Reset" onclick="document.forms[0].reset()">
    對(duì)文本框進(jìn)行腳本編寫
      獲取/更改文本框的值
      選擇文本
        <input type="button" value="選擇文本" onclick="selectText()">
      文本框事件
        <input type="text" name="textbox1" value="" onselect="alert('select')" />
      自動(dòng)選擇文本
        <input type="text" onfocus="this.select()" />
        <textarea onfocus="this.select()"></textarea>
    對(duì)列表框和組合框進(jìn)行腳本編寫
      訪問(wèn)選項(xiàng)
      獲取/更改選中項(xiàng)
      添加選項(xiàng)
        var ListUtil = new Object();
        ListUtil.add = function(oListbox, sName, sValue){option.appendChild(document.createTextNode(sName));}
      刪除選項(xiàng)
        var oListbox = document.getElementsById("selListbox");
        oListbox.remove(0); //移除一個(gè)選項(xiàng)
      移動(dòng)選項(xiàng)
      重新排序選項(xiàng)
    對(duì)復(fù)選框和單選框進(jìn)行腳本編寫
      得到單選框的值
        <input type="radio" id="male" name="gender" value="male">男</input>
        document.getElementById("male").value
      得到復(fù)選框的值
    表單驗(yàn)證
      使用submit事件在錯(cuò)誤發(fā)生之后捕獲錯(cuò)誤
      使用change事件在錯(cuò)誤發(fā)生時(shí)捕獲
      使用keypress事件在錯(cuò)誤發(fā)生之前捕獲錯(cuò)誤
      表單效驗(yàn)最佳實(shí)踐
        必須對(duì)用戶有幫助
        不要讓人討厭
        只要有可能,就用HTML功能代替javascript
        一次顯示所有錯(cuò)誤
        早點(diǎn)捕獲錯(cuò)誤
        如果拿不準(zhǔn),就不要太嚴(yán)格
------------------------------------------------代碼實(shí)例:
<script type="text/javascript">
//function validate(){
// var user = document.getElementById("user");
// user.disabled="true";   //表示不可用
// user.focus(); //得到焦點(diǎn)
//      onfocus="validate();" //當(dāng)某個(gè)文本框得到焦點(diǎn)時(shí)觸發(fā)
//     onblur="validate()"    //當(dāng)某個(gè)文本框失去焦點(diǎn)時(shí)觸發(fā)
///}
//獲取表單的四種方式
//function validate(){
   //var form1 = document.getElementById("form1");
   //var form = document.forms[0];
   //var form = document.forms["form1"];
   //var form = document.form1;
   //alert(form==form1)
//獲取表單中的元素
//var a = form1.user;
//var a = form1.elements[0];
//var a = form1.elements["user"];
//alert(a.value)
//表單提交
//form1.submit();
//}
//獲取單選框的值
// function validate(){
// var form1 = document.getElementById("form1");
   //var user = form1.user;
   //user.focus();
   //user.select(); //選中文本框的內(nèi)容
   //var rName = document.getElementsByName("radioName");
// var a = form1.radioName;
// for(var i=0;i<a.length;i++){
// if(a[i].checked){
//   alert(a[i].value)
// }
// }
//}
//獲取復(fù)選框的值
/** function validate(){
     var form1 = document.getElementById("form1");
     var check = form1.checkName;
     for(var i=0;i<check.length;i++){
      if(check[i].checked){
       alert(check[i].value)
      }
     }
   }**/
  
   function validate(){
   
   }
//onchange事件
   function chage(){
    var user = document.getElementById("user");
    if(user.value==""){
     document.getElementById("span1").innerHTML="用戶名不能為null";
     user.focus();
     return false;
    }else{
     document.getElementById("span1").innerHTML="用戶名合法";
     return ture;
    }
   }
</script>
<img name="img1" src="C:\Documents and Settings\黃\桌面\1.jpg" width="200px" height="200px">
  
   <select onchange="document.img1.src=options[selectedIndex].value">
    <option value="C:\Documents and Settings\黃\桌面\ff.gif">敬敬</option>
    <option value="C:\Documents and Settings\黃\桌面\ff.gif">敬敬</option>
    <option value="C:\Documents and Settings\黃\桌面\1.jpg">敬敬</option>
   </select>
Document對(duì)象在檢驗(yàn)表單中的作用
在制作登錄表單驗(yàn)證的過(guò)程中,我們經(jīng)常要用到Document函數(shù)對(duì)象,這是JavaScript非常重要的函數(shù)。W3C把它納入DOM文檔模型對(duì)象中。可以說(shuō)它是元素操作的一個(gè)十分重要的方法。
此函數(shù)的語(yǔ)法代碼如下:
Document.ement.chosts.x   //x可表示為屬性也可表示為方法。
如要表示表單reg中名字輸入框name的文本內(nèi)容:document.reg.name.value
要讓輸入框獲得焦點(diǎn):代碼格式為document.reg.name.focus()
下面是一段典型的驗(yàn)證輸入函數(shù)代碼:
<script language="javascript">
function chekname(){
       name=document.reg.name.value;
if(name==""){
              alert("請(qǐng)輸入昵稱!");
       document.reg.name.vlaue=focus(); 或document.reg.name.focus() ;
       return false;
}else{
       open("chkname.php?name="+name+"","chk","noscrollbars=no,width=200,height=50,top=200,left=200");
}
}    
</script>
此段自定義函數(shù)的意思是驗(yàn)證輸入框是不是空白,若不是空白則打開(kāi)一個(gè)名為“chk”帶有傳遞參數(shù)的窗口進(jìn)一步驗(yàn)證用戶名是不是合法。
Document對(duì)象在檢驗(yàn)表單中的作用


強(qiáng)強(qiáng) 2013-05-31 08:00 發(fā)表評(píng)論
]]>
分享到QQ個(gè)人空間http://www.aygfsteel.com/lyjjq/articles/399357.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Thu, 16 May 2013 06:59:00 GMThttp://www.aygfsteel.com/lyjjq/articles/399357.htmlhttp://www.aygfsteel.com/lyjjq/comments/399357.htmlhttp://www.aygfsteel.com/lyjjq/articles/399357.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/399357.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/399357.html(function(){
var p = {
url:location.href,
showcount:'1',/*是否顯示分享總數(shù),顯示:'1',不顯示:'0' */
desc:'',/*默認(rèn)分享理由(可選)*/
summary:'',/*分享摘要(可選)*/
title:'',/*分享標(biāo)題(可選)*/
site:'',/*分享來(lái)源 如:騰訊網(wǎng)(可選)*/
pics:'', /*分享圖片的路徑(可選)*/
style:'203',
width:98,
height:22
};
var s = [];
for(var i in p){
s.push(i + '=' + encodeURIComponent(p[i]||''));
}
document.write(['<a version="1.0" class="qzOpenerDiv" href="})();
</script>
<script src="


強(qiáng)強(qiáng) 2013-05-16 14:59 發(fā)表評(píng)論
]]>
JQuery1.9參考http://www.aygfsteel.com/lyjjq/articles/397529.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Mon, 08 Apr 2013 07:51:00 GMThttp://www.aygfsteel.com/lyjjq/articles/397529.htmlhttp://www.aygfsteel.com/lyjjq/comments/397529.htmlhttp://www.aygfsteel.com/lyjjq/articles/397529.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/397529.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/397529.html<p style="margin: 18px 5px; padding: 13px 24px 13px 20px; line-height: 24px; font-family: 微軟雅黑, Arial, 宋體; border-top-color: rgb(229, 229, 229); border-bottom-color: rgb(229, 229, 229); border-top-width: 1px; border-bottom-width: 1px; border-top-style: solid; border-bottom-style: solid; background-color: rgb(251, 251, 251);" id="intro">jQuery&nbsp;1.9刪除或修改了幾個(gè)過(guò)去行為不一致或效率低下的幾個(gè)API。他們?cè)谝郧暗膉Query版本中已經(jīng)標(biāo)注過(guò)過(guò)時(shí)(deprecated)的API,特別是1.7和1.8。</p>
<div style="margin: auto; width: 620px; line-height: 25px; font-family: 微軟雅黑, Arial, 宋體; background-color: rgb(255, 255, 255);" id="content">
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">jQuery 1.9刪除或修改了幾個(gè)過(guò)去行為不一致或效率低下的幾個(gè)API。他們?cè)谝郧暗膉Query版本中已經(jīng)標(biāo)注過(guò)過(guò)時(shí)(deprecated)的API,特別是1.7和1.8。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">在做這些變化中,團(tuán)隊(duì)的目標(biāo)是修復(fù)jQuery的行為不一致或比較難使用的地方,在這個(gè)過(guò)程中提高整體性能,減小了文件的體積。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">此列表是看似給你一些不祥的預(yù)感。因?yàn)閖Query 1.9刪除和修改一些以前做特殊需求的API,比如jQuery.browser。如何升級(jí)?首先,看看你的代碼,最好的方法是嘗試用jQuery 1.9和Migrate(遷移)插件(如下文所述)。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">本指南作為標(biāo)準(zhǔn)的jQuery API文檔的附錄,作為快速上手jQuery 1.9的引導(dǎo)。</p>
<h2>jQuery Migrate(遷移)插件</h2>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">我們認(rèn)識(shí)到,現(xiàn)有的網(wǎng)站和插件可能會(huì)受到這些變化的影響,所以提供一個(gè)過(guò)渡性的升級(jí)路徑&#8212;&#8212;&nbsp;jQuery Migrate(遷移)插件。下面的說(shuō)明中,在1.9中變化或刪除的API,大部分可以使用jQuery Migrate(遷移)插件恢復(fù)。請(qǐng)注意,jQuery 1.9中所有的變化也將應(yīng)用到j(luò)Query 2.0中,jQuery Migrate(遷移)插件在jQuery2.0中也是可用的。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">未壓縮,開(kāi)發(fā)版本的jQuery Migrate(遷移)插件使用時(shí)會(huì)在控制臺(tái)中顯示警告信息,詳細(xì)的指出不兼容或刪除等信息及解決方法。這使得它在現(xiàn)有的jQuery代碼和插件上查找和修復(fù)問(wèn)題時(shí)非常有用。jQuery Migrate(遷移)插件包含了1.6.4以來(lái)存在但1.9已不支持所有API。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">壓縮版本的的jQuery Migrate(遷移)插件,不會(huì)在瀏覽器控制臺(tái)中產(chǎn)生任何不兼容或刪除等信息,并且可以在jQuery 1.9或更高版本,或者舊的不兼容的jQuery代碼或插件中使用。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">理想情況下,這將只能作為一個(gè)短期的解決方案,但是這要你自己做出決定。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">更多的信息請(qǐng)參見(jiàn):&nbsp;jQuery Migrate plugin。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:哥過(guò)一句嘴,盡早的修改原來(lái)不兼容的代碼,畢竟使用jQuery Migrate(遷移)插件不是一個(gè)長(zhǎng)久之計(jì)啊。</p>
<h2>jQuery1.9中改變的地方</h2>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">下面列表中說(shuō)的并不代表jQuery 1.9中所有改變,只是我們預(yù)期的改變。完整的,詳細(xì)的更改列表,請(qǐng)參閱jQuery的博客或訪問(wèn)bugs.jquery.com中發(fā)布的公告。</p>
<h4>.toggle(function, function, &#8230; ) 方法刪除</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">這個(gè)方法綁定兩個(gè)或多個(gè)處理程序到匹配的元素,用來(lái)執(zhí)行交替的點(diǎn)擊事件。它不應(yīng)該被混同于顯示或隱藏匹配元素.toggle( )方法,因?yàn)樗鼪](méi)有過(guò)時(shí)。前者被刪除,以減少混亂和提高模塊化程度。jQuery Migrate(遷移)插件可以恢復(fù)此功能。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API&nbsp;http://www.css88.com/jqapi-1.9/toggle-event/</p>
<h4>jQuery.browser() 方法刪除</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">jQuery.browser()方法從jQuery 1.3開(kāi)始已經(jīng)過(guò)時(shí)了,在1.9中被刪除。 如果需要的話,jQuery Migrate(遷移)插件可以恢復(fù)此功能。我們建議如特征檢測(cè),請(qǐng)使用Modernizr庫(kù)。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API &nbsp;http://www.css88.com/jqapi-1.9/jQuery.browser/</p>
<h4>.live() 方法移除</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">.live()方法從jQuery 1.7開(kāi)始已經(jīng)過(guò)時(shí)了,在1.9中被刪除。 我們建議使用.on()方法來(lái)替換升級(jí)你的代碼。要完全匹配$(&#8220;a.foo&#8221;).live(&#8220;click&#8221;, fn),例如,你可以寫$(document).on(&#8220;click&#8221;, &#8220;a.foo&#8221;, fn)(譯者注:因?yàn)樵瓉?lái)的live事件其實(shí)是綁定在文檔document上的)。有關(guān)詳細(xì)信息,請(qǐng)參閱.on()文檔。在此期間,你可以使用jQuery Migrate(遷移)插件來(lái)恢復(fù).live() 功能。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API &nbsp;http://www.css88.com/jqapi-1.9/on/&nbsp;和&nbsp;&nbsp;http://www.css88.com/jqapi-1.9/live/</p>
<h4>.die() 方法移除</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">.die()方法從jQuery 1.7開(kāi)始已經(jīng)過(guò)時(shí)了,在1.9中被刪除。 我們建議使用. off()方法來(lái)替換升級(jí)你的代碼。要完全匹配$(&#8220;a.foo&#8221;).die(&#8220;click&#8221;),例如,你可以寫$(document).off(&#8220;click&#8221;, &#8220;a.foo&#8221;)。有關(guān)詳細(xì)信息,請(qǐng)參閱.off()文檔。在此期間,你可以使用jQuery Migrate(遷移)插件來(lái)恢復(fù). die() 功能。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API &nbsp;http://www.css88.com/jqapi-1.9/off/&nbsp;和&nbsp;http://www.css88.com/jqapi-1.9/die/</p>
<h4>jQuery.sub() 方法移除</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">jQuery.sub()方法被移到j(luò)Query Migrate(遷移)插件中。使用的頻率證明它沒(méi)有必要再保留在核心代碼庫(kù)中,jQuery Migrate(遷移)插件添加了此功能。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API&nbsp;http://www.css88.com/jqapi-1.9/jQuery.sub/</p>
<h4>.add() 方法修改</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">.add()方法返回的結(jié)果總是按照節(jié)點(diǎn)在document(文檔)中的順序排列。在1.9之前,如果上下文或輸入的集合中任何一個(gè)以脫離文檔的節(jié)點(diǎn)(未在文檔中)開(kāi)始,使用.add()方法節(jié)點(diǎn)不會(huì)按照document(文檔)中的順序排序。現(xiàn)在,返回的節(jié)點(diǎn)按照文檔中的順序排序,并且脫離文檔的節(jié)點(diǎn)被放置在集合的末尾。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API&nbsp;http://www.css88.com/jqapi-1.9/add/</p>
<h4>.addBack(selector) 替換 .andSelf()</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">從jQuery1.8開(kāi)始,.andSelf()方法已經(jīng)被標(biāo)注過(guò)時(shí),在jQuery1.8和更高版本中應(yīng)使用.addBack()。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">我們認(rèn)為對(duì)于&#8220;添加并返回&#8221;以前的結(jié)果集合這是一個(gè)更好的名字。新方法可以接受一個(gè)可選的選擇器,該選擇器可以用來(lái)過(guò)濾之前集合,將它添加到當(dāng)前集合并返回。$(&#8220;section, aside&#8221;).children(&#8220;ul&#8221;).addBack(&#8220;aside&#8221;) 會(huì)根據(jù)他們?cè)谖臋n中的順序,得到section與aside下所有ul子元素,外加所有aside元素。雖然.addSelf()在1.9中仍然可以使用,我們建議您盡快修改名稱。如果使用.addSelf(),jQuery Migrate插件會(huì)提出警告。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API&nbsp;http://www.css88.com/jqapi-1.9/andSelf/&nbsp;和&nbsp;http://www.css88.com/jqapi-1.9/addBack/</p>
<h4>.after(), .before(), 和 .replaceWith()使用脫離文檔的節(jié)點(diǎn)</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">1.9以前,.after(), .before(), 和 .replaceWith()將嘗試在當(dāng)前的jQuery集合中添加或改變節(jié)點(diǎn),如果在當(dāng)前的jQuery集的節(jié)點(diǎn)未連接到文檔(注:即脫離文檔的節(jié)點(diǎn)),在這種情況下,返回一個(gè)新的jQuery集合,而不是原來(lái)的那個(gè)集合。這將產(chǎn)生一些前后矛盾和徹底的錯(cuò)誤 &#8211; 該方法可能會(huì),也可能不會(huì)返回一個(gè)新的結(jié)果,這取決于它的參數(shù)!從1.9開(kāi)始,這些方法總是返回原始未修改集并且試圖在一個(gè)沒(méi)有父節(jié)點(diǎn)的節(jié)點(diǎn)上使用.after(), .before(), or .replaceWith() 有沒(méi)有任何效果 &#8211; 即這個(gè)集或它包含的節(jié)點(diǎn)兩者都不被改變。</p>
<h4>.appendTo, .insertBefore, .insertAfter, 和 .replaceAll</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">在1.9中,這些方法總是返回一個(gè)新的集合,使他們可以使用的鏈?zhǔn)秸{(diào)用和.end()方法。1.9之前,只有當(dāng)他們是一個(gè)單獨(dú)的目標(biāo)元素時(shí),他們將返回舊的集合。需要注意的是這些方法總是返回所有元素附加到目標(biāo)元素的聚合集合。如果沒(méi)有元素被目標(biāo)選擇器選中(例如,$(elements).appendTo(&#8220;#not_found&#8221;))那么返回的集合是空的。</p>
<h4>AJAX 事件需要綁定到document</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">在jQuery 1.9中, 全局的AJAX事件(ajaxStart, ajaxStop, ajaxSend, ajaxComplete, ajaxError, and ajaxSuccess) 只能在document元素上觸發(fā)。修改AJAX事件監(jiān)聽(tīng)程序到document元素上。例如,如果目前的代碼看起來(lái)像這樣:</p>
<div style="margin: 0px;" id="highlighter_117962">
<div style="margin: 0px;">
<div style="margin: 0px;">
<table style="margin: 0px; padding: 0px;">
    <tbody style="margin: 0px; padding: 0px;">
        <tr style="margin: 0px; padding: 0px;">
            <td style="margin: 0px; padding: 0px;">1</td>
            <td style="margin: 0px; padding: 0px;">$("#status").ajaxStart(function(){ $(this).text("Ajax started"); });</td>
        </tr>
    </tbody>
</table>
</div>
</div>
</div>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">修改成:</p>
<div style="margin: 0px;" id="highlighter_160461">
<div style="margin: 0px;">
<div style="margin: 0px;">
<table style="margin: 0px; padding: 0px;">
    <tbody style="margin: 0px; padding: 0px;">
        <tr style="margin: 0px; padding: 0px;">
            <td style="margin: 0px; padding: 0px;">1</td>
            <td style="margin: 0px; padding: 0px;">$(document).ajaxStart(function(){ $("#status").text("Ajax started"); });</td>
        </tr>
    </tbody>
</table>
</div>
</div>
</div>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API&nbsp;http://www.css88.com/jqapi-1.9/category/ajax/global-ajax-event-handlers/</p>
<h4>.trigger() &#8220;click&#8221; 事件時(shí)Checkbox/radio 的狀態(tài)</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">當(dāng)用戶點(diǎn)擊一個(gè)復(fù)選框或單選按鈕時(shí),如果節(jié)點(diǎn)上沒(méi)調(diào)用event.preventDefault(),事件處理程序中會(huì)根據(jù)復(fù)選框或單選按的當(dāng)前狀態(tài)判斷并且得到它的新?tīng)顟B(tài)。因此,例如,如果用戶點(diǎn)擊一個(gè)未選中的checkbox,事件處理程序?qū)⑦x中(checked)這個(gè)checkbox。1.9之前,.trigger(&#8220;click&#8221;) 或 .click()任何一個(gè)將觸發(fā)一個(gè)合成事件,根據(jù)用戶點(diǎn)擊行為,我們可以看到checkbox與實(shí)際checked屬性相反的狀態(tài)。在1.9中修復(fù)了這個(gè)bug,用戶行為會(huì)得到相應(yīng)的狀態(tài)。</p>
<h4>focus事件觸發(fā)順序</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">當(dāng)用戶再表單元素上點(diǎn)擊或者按tab鍵,使元素獲取焦點(diǎn),瀏覽器首先在焦點(diǎn)元素上觸發(fā)一個(gè)blur(失去焦點(diǎn))事件,然后在新元素上觸發(fā)一個(gè)focus(獲取焦點(diǎn))事件。在1.9之前,使用.trigger(&#8220;focus&#8221;) 或 .focus() 綁定一個(gè)focus事件,新元素將觸發(fā)一個(gè)focus事件,然后觸發(fā)先前焦點(diǎn)元素的blur事件,1.9已修正此問(wèn)題。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">如果目標(biāo)元素沒(méi)有獲取焦點(diǎn)并且可以成功的獲取焦點(diǎn)(譯者注:比如disabled被禁用的表單元素獲取不到焦點(diǎn)),那么使用DOM原生的focus事件,瀏覽器只訪問(wèn)focus事件處理程序。jQuery總是調(diào)用.trigger(&#8220;focus&#8221;) 或 .focus()綁定的處理程序,無(wú)論元素是否獲取焦點(diǎn)。在jQuery 1.9中還是這樣處理的。和DOM的.focus()方法不同之處在于,在許多情況下,元素已經(jīng)獲取焦點(diǎn)或者元素被禁用,DOM的.focus()方法不會(huì)調(diào)用事件處理程序。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">不幸的是,所有版本的Internet Explorer(6-10)觸發(fā)焦點(diǎn)事件是異步的。當(dāng)你在IE中使用.trigger(&#8220;focus&#8221;),jQuery無(wú)法&#8220;預(yù)知&#8221;異步focus事件以后會(huì)發(fā)生什么。所以它總是會(huì)觸發(fā)一個(gè)自己的focus事件,以確保功能正常。這可能會(huì)造成focus事件重覆執(zhí)行,建議改用DOM內(nèi)建的focus()較單純,例如: $(&#8220;#boo&#8221;).get(0).focus()。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API&nbsp;http://www.css88.com/jqapi-1.9/focus/</p>
<h4>jQuery(htmlString)與jQuery(selectorString)</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">在1.9以前,如果一個(gè)字符串中有任何HTML標(biāo)簽,那么這個(gè)字符串將被認(rèn)為是一個(gè)HTML字符串。這有可能造成意外的代碼執(zhí)行和拒絕有效的選擇器字符串。 1.9開(kāi)始,以一個(gè)小于號(hào)(&#8220;&lt;&#8221;)字符開(kāi)頭的字符串才被認(rèn)為是HTML字符串。Migrate(延遲)插件可以恢復(fù)到1.9以前的行為。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">如果一個(gè)字符串被認(rèn)為是HTML,但可能會(huì)以不是一個(gè)HTML標(biāo)簽的任意文本開(kāi)始,將它傳遞給jQuery.parseHTML()將返回一個(gè)DOM節(jié)點(diǎn)數(shù)組表示的標(biāo)記。我們可以通過(guò)它來(lái)創(chuàng)建一個(gè)jQuery集合,例如:$($.parseHTML(htmlString))。例如,在處理HTML模板方面這被認(rèn)為是最佳實(shí)踐。簡(jiǎn)單使用文字字符串,如$(&#8220;&lt;p&gt;Testing&lt;/p&gt;&#8221;).appendTo(&#8220;body&#8221;)不會(huì)受此影響。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">總之:HTML字符串傳遞給jQuery(),除了以一個(gè)小于號(hào)(&#8220;&lt;&#8221;)字符開(kāi)始以外的其他字符串都將被解釋為一個(gè)選擇器。因?yàn)樽址ǔ2荒鼙唤忉尀橐粋€(gè)選擇器,最有可能的結(jié)果是Sizzle選擇器引擎錯(cuò)誤拋出的&#8220;無(wú)效的選擇器語(yǔ)法&#8221;。使用jQuery.parseHTML()來(lái)解析任意的HTML。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">使用jQuery Migrate(遷移)插件,如果該字符串傳遞給$(),&#8220;看起來(lái)像HTML&#8221;,它會(huì)使用舊的規(guī)則來(lái)確定。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API&nbsp;http://www.css88.com/jqapi-1.9/jQuery/</p>
<h4>.data()中名稱包含點(diǎn)(&#8220;.&#8221;)改變</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">.data()有一個(gè)未公開(kāi)并且令人難以置信的非高性能監(jiān)控值的設(shè)置和獲取,1.9中被移除。這已經(jīng)影響到了包含點(diǎn)的數(shù)據(jù)名稱的解析。從1.9開(kāi)始,調(diào)用 .data(&#8220;abc.def&#8221;)只能通過(guò)名稱為&#8220;abc.def&#8221;檢索數(shù)據(jù),原本還可以通過(guò)&#8220;abc&#8221;取得的技巧已被取消。需要注意的是較低級(jí)別的jQuery.data()方法不支持事件,所以它并沒(méi)有改變。即使使用jQuery Migrate(遷移)插件也恢復(fù)不到原來(lái)的行為。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API&nbsp;http://www.css88.com/jqapi-1.9/data/</p>
<h4>脫離文檔節(jié)點(diǎn)在jQuery集合中的順序</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">對(duì)于許多版本,幾乎所有的jQuery的方法,返回一組新的節(jié)點(diǎn)集合,這個(gè)集合是一個(gè)使用他們?cè)谖臋n中順序排序的結(jié)果集。(有幾個(gè)方法,如.parents()返回的結(jié)果是他們?cè)谖臋n反向順序排序,但在1.9中這些例外情況已經(jīng)記錄并沒(méi)有改變。)</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">在1.9之前,若jQuery集合中混雜DOM的節(jié)點(diǎn)及未放進(jìn)DOM的脫離文檔節(jié)點(diǎn),則可能出現(xiàn)不可預(yù)期的隨機(jī)排序。從1.9開(kāi)始,在文檔中的連接節(jié)點(diǎn)都總是按文檔順序放置在集合的開(kāi)頭,脫離文檔節(jié)點(diǎn)被放置在他們的后面。即使使用jQuery Migrate(遷移)插件也恢復(fù)不到原來(lái)的行為。</p>
<h4>加載并且執(zhí)行HTML內(nèi)容中的scripts</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">在1.9之前,任何接受HTML字符串的方法(例如,$()、.append()、.wrap())會(huì)執(zhí)行HTML字符串中所包含的Script,并且將它們從文檔中移除,以防止他們?cè)俅伪粓?zhí)行。在特殊情況下,使用這些方法一個(gè)腳本可能會(huì)被移除并重新插入到文檔中,比如.wrap()。從1.9開(kāi)始,插入到文檔的腳本會(huì)執(zhí)行,但仍然保留在文檔中并且標(biāo)記為已經(jīng)被執(zhí)行過(guò)的,這樣它們就不會(huì)被再次執(zhí)行,即使它們被刪除并重新插入。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">盡管這種變化,在HTML標(biāo)記中混合可執(zhí)行的JavaScript是非常不好的習(xí)慣;它對(duì)設(shè)計(jì),安全性,可靠性和性能有影響。例如,外部腳本標(biāo)簽包含在HTML中同步地取出,然后評(píng)估執(zhí)行,這可能需要大量的時(shí)間。沒(méi)有任何接口通知這些腳本何時(shí)何地加載,或者當(dāng)有錯(cuò)誤產(chǎn)生的時(shí)候獲得糾正提示。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">試圖通過(guò)克隆一個(gè)現(xiàn)有的腳本標(biāo)簽加載和注入腳本,克隆到文檔將不再起作用,因?yàn)榭寺〉哪_本標(biāo)記已經(jīng)被標(biāo)記為已執(zhí)行。要加載一個(gè)新的腳本,建議使用jQuery.getScript()代替。</p>
<h4>.attr() 和 .prop()對(duì)比</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:@caikan的建議,在這里將property翻譯成了&#8220;對(duì)象屬性&#8221;,以區(qū)別attributes(標(biāo)簽屬性),后面括號(hào)標(biāo)注了原文。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">jQuery 1.6 介紹了.prop()方法設(shè)置或獲取節(jié)點(diǎn)上的對(duì)象屬性(property),并且不建議使用.attr()方法設(shè)置對(duì)象屬性(property)。然而版本一直到1.9,在某些特殊情況下繼續(xù)支持使用.attr()方法。當(dāng)選擇器是用來(lái)區(qū)分標(biāo)簽屬性(attributes)和對(duì)象屬性(properties)時(shí),這種行為在向后兼容的命名方面會(huì)引起混亂。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">例如,一個(gè)復(fù)選框的布爾標(biāo)簽屬性(attributes),如checked和disabled受到這種變化的影響。&#8221;input[checked]&#8220;的正確行為是選擇有checked屬性的復(fù)選框,不管是它的字符串值,還是它當(dāng)前的狀態(tài)。與此相反, &#8220;input:checked&#8221; 選擇當(dāng)前checked屬性的布爾值(true或false)為true的復(fù)選框,例如當(dāng)用戶單擊復(fù)選框時(shí),會(huì)受到影響。1.9之前版本這些選擇器有時(shí)不選擇正確的節(jié)點(diǎn)。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">這里有一些例子,當(dāng)在復(fù)選框上設(shè)置一個(gè)checked屬性時(shí)正確的和不正確的使用方法;同樣的規(guī)則也適用于disabled屬性。請(qǐng)注意只有對(duì)象屬性(property)在所有的瀏覽器始終反映和更新的復(fù)選框的當(dāng)前狀態(tài);你很少會(huì)需要設(shè)置的屬性(attribute)。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">// Correct if changing the attribute is desired</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">$(elem).attr("checked", "checked");</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">// Correct for checking the checkbox</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">$(elem).prop("checked", true);</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">// Correct if removing the attribute is desired</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">$(elem).removeAttr("checked");</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">// Correct for clearing the checkbox</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">$(elem).prop("checked", false);<br style="margin: 0px; padding: 0px;" />
&nbsp;</p>
<div style="margin: 0px;" id="highlighter_656602">
<div style="margin: 0px;">input元素的特性(property)和標(biāo)簽屬性(attribute)是這個(gè)歧義的另一個(gè)例子。標(biāo)簽屬性(attribute)一般體現(xiàn)讀取HTML標(biāo)記的值;屬性反映了當(dāng)前值。由于.val()方法是jQuery推薦的用來(lái)獲取或設(shè)置表單元素的值的方式,這種混淆通常不會(huì)影響用戶。</div>
</div>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">然而,當(dāng)一個(gè)選擇器,如&#8221;input[value=abc]&#8221; 被使用,它應(yīng)該始終選擇的value標(biāo)簽屬性(attribute)并且用戶對(duì)于對(duì)象屬性(property)沒(méi)有任何改變,例如,從這些選擇器中鍵入到一個(gè)文本輸入框。從jQuery 1.9開(kāi)始,此行為正確并且一貫的。早期jQuery版本當(dāng)應(yīng)該使用標(biāo)簽屬性(attribute),有時(shí)會(huì)使用他們的對(duì)象屬性(property)。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">jQuery Migrate(遷移)插件可以恢復(fù)原來(lái)的對(duì)象屬性(property)和標(biāo)簽屬性(attribute)規(guī)則。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API&nbsp;http://www.css88.com/jqapi-1.9/attr/&nbsp;和&nbsp;http://www.css88.com/jqapi-1.9/prop/</p>
<h4>老IE中的$(&#8220;input&#8221;).attr(&#8220;type&#8221;, newValue)</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">在1.9版之前, 在所有的瀏覽器中,任何企圖設(shè)置一個(gè)input或者button元素的類型(type屬性),jQuery都將拋出一個(gè)異常。這樣做時(shí)為了符合最低標(biāo)準(zhǔn)的兼容;因?yàn)槿绻阍噲D改變input元素的類型,IE6/7/8拋出一個(gè)錯(cuò)誤。從 jQuery 1.9開(kāi)始,如果瀏覽器允許的話,我們?cè)试S您設(shè)置元素的類型。但是,你需要知道自己的代碼,在老IE(IE6/7/8)下試圖做到這一點(diǎn)還是會(huì)拋出一個(gè)錯(cuò)誤。當(dāng)你試圖設(shè)置類型屬性時(shí),jQuery Migrate(遷移)插件會(huì)發(fā)出警告,但不會(huì)拋出一個(gè)JavaScript錯(cuò)誤。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API&nbsp;http://www.css88.com/jqapi-1.9/attr/</p>
<h4>&#8220;hover&#8221;偽事件</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">從1.9開(kāi)始,事件名稱字符串&#8220;hover&#8221;不再支持為&#8220;mouseenter mouseleave&#8221;的代名詞縮寫。允許應(yīng)用程序綁定和觸發(fā)自定義的&#8221;hover&#8221;事件。修改現(xiàn)有的代碼是一個(gè)簡(jiǎn)單的查找/替換,并且jQuery Migrate(延遲)插件可以恢復(fù)&#8221;hover&#8221;偽事件。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API&nbsp;http://www.css88.com/jqapi-1.9/hover/</p>
<h4>jQuery對(duì)象上的.selector屬性</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">jQuery對(duì)象上過(guò)時(shí)的selector屬性保留的目的是為了支持過(guò)時(shí)的.live()事件。在1.9中,jQuery不再試圖在鏈方法上保留這個(gè)屬性,因?yàn)?.9已經(jīng)移除了.live()事件。不要使用jQuery對(duì)象的.selector屬性。jQuery Migrate(遷移)插件也沒(méi)支持這個(gè)屬性。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API&nbsp;http://www.css88.com/jqapi-1.9/selector/</p>
<h4>jQuery.attr()</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">1.9版移除了jQuery.attr(elem, name, value, pass)方法,用jQuery Migrate(遷移)插件可恢復(fù)這個(gè)方法。</p>
<h4>jQuery.ajax返回一個(gè)空字符串的JSON結(jié)果</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">1.9之前,一個(gè)AJAX調(diào)用預(yù)期返回JSON或JSONP的數(shù)據(jù)類型,當(dāng)返回值是一個(gè)空字符串時(shí)會(huì)被認(rèn)為是成功的狀態(tài),但返回一個(gè)null給success處理程序或承諾(promise)。從1.9開(kāi)始,JSON數(shù)據(jù)返回一個(gè)空字符串被認(rèn)為是畸形的JSON(因?yàn)樗緛?lái)就是);這將拋出一個(gè)錯(cuò)誤。這種情況下,使用error(錯(cuò)誤)處理程序捕獲。</p>
<h4>jQuery.proxy()</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">1.9版前,$.proxy(null, fn)、$.proxy(undefined, fn)的this會(huì)指向window,而$.proxy(false, fn)的this則指向new Boolean(false) ;1.9起若context傳入null/undefined/false,函數(shù)的this會(huì)維持原先context,不被改變。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API&nbsp;http://www.css88.com/jqapi-1.9/jQuery.proxy/</p>
<h4>.data(&#8220;events&#8221;)</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">1.9以前,如果沒(méi)有其他的代碼定義一個(gè)名稱為&#8220;events&#8221;的數(shù)據(jù)元素,.data(&#8220;events&#8221;) 可以用來(lái)檢索一個(gè)元素上,jQuery未公開(kāi)的內(nèi)部事件數(shù)據(jù)結(jié)構(gòu)。這種特殊的情況,在1.9中已被刪除。沒(méi)有公共的接口來(lái)獲取這個(gè)內(nèi)部數(shù)據(jù)結(jié)構(gòu),</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">它是不公開(kāi)的。jQuery Migrate(遷移)插件可以恢復(fù)原來(lái)的行為。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API&nbsp;http://www.css88.com/jqapi-1.9/data/</p>
<h4>移除Event對(duì)象的部分屬性</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">Event對(duì)象的attrChange、attrName、realtedNote和srcElement屬性自1.7版因無(wú)法跨瀏覽器已被宣告過(guò)時(shí);從jQuery 1.9開(kāi)始,它們不再被復(fù)制到Event對(duì)象傳遞給事件處理程序。在jQuery所有版本中,這些屬性依然可以在支持他們的瀏覽器上通過(guò)event.orginalEvent存取,以取代event。jQuery Migrate(遷移)插件在Event對(duì)象有加回了這些屬性。</p>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">譯者注:具體查看API&nbsp;http://www.css88.com/jqapi-1.9/category/events/event-object/</p>
<h4>API方法未公開(kāi)的參數(shù)</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">1.9之前,幾個(gè)API方法未公開(kāi)改變了他們的行為的參數(shù),并存在潛在的意外誤用。這些參數(shù)已經(jīng)被刪除。受影響的方法包括jQuery.data(),jQuery.removeData(),和jQuery.attr()。jQuery Migrate(遷移)插件也不支持的代碼。</p>
<h4>其他未公開(kāi)的屬性和方法</h4>
<p style="margin: 20px 0px; padding: 0px; line-height: 1.8em; text-indent: 2em;">下面的內(nèi)部屬性和方法從未被收入到文檔,并已在1.9中刪除。</p>
<ul style="list-style: none; margin: 0px; padding: 0px;">
    <li style="margin: 0px 0px 0px 2em; padding: 0px; list-style-type: disc;">jQuery.deletedIds</li>
    <li style="margin: 0px 0px 0px 2em; padding: 0px; list-style-type: disc;">jQuery.uuid</li>
    <li style="margin: 0px 0px 0px 2em; padding: 0px; list-style-type: disc;">jQuery.attrFn</li>
    <li style="margin: 0px 0px 0px 2em; padding: 0px; list-style-type: disc;">jQuery.clean()</li>
    <li style="margin: 0px 0px 0px 2em; padding: 0px; list-style-type: disc;">jQuery.event.handle()</li>
    <li style="margin: 0px 0px 0px 2em; padding: 0px; list-style-type: disc;">jQuery.offset.bodyOffset()</li>
</ul>
</div>


強(qiáng)強(qiáng) 2013-04-08 15:51 發(fā)表評(píng)論
]]>
ul li CSS 樣式http://www.aygfsteel.com/lyjjq/articles/396337.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Tue, 12 Mar 2013 09:51:00 GMThttp://www.aygfsteel.com/lyjjq/articles/396337.htmlhttp://www.aygfsteel.com/lyjjq/comments/396337.htmlhttp://www.aygfsteel.com/lyjjq/articles/396337.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/396337.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/396337.html


列表是HTML里一種很有用的顯示方式,可以把相關(guān)的并列內(nèi)容整齊地垂直排列,使網(wǎng)頁(yè)顯得整潔專業(yè),并讓瀏覽者有一目了然的感覺(jué)。
樣式表為列表增加了一些功能,控制列表的樣式包括列表樣式、圖形符號(hào)、列表位置三個(gè)部分。
1.列表符號(hào)
列表符號(hào)是指顯示于每一個(gè)列表項(xiàng)目前的符號(hào)標(biāo)識(shí)。
基本格式如下:
list-style-type:參數(shù)
參數(shù)取值范圍:
·disc:圓形
·circle:空心圓
·square:方塊
·decimal:十進(jìn)制數(shù)字
·lower-roman:小寫羅馬數(shù)字
·upper-roman:大寫羅馬數(shù)字
·lower-alpha:小寫希臘字母
·upper-alpha:大寫希臘字母
·none:無(wú)符號(hào)顯示
參數(shù)中的disc是默認(rèn)選項(xiàng)。

2.圖形符號(hào)
圖形符號(hào)指原來(lái)列表的項(xiàng)目符號(hào)將可以使用圖形來(lái)代替。
基本格式如下:
list-style-image:URL
URL是用來(lái)代替項(xiàng)目符號(hào)的圖形文件的地址,可以使用相對(duì)地址或絕對(duì)地址。
3.列表位置
列表位置描述列表在何處顯示。
基本格式如下:
list-style-position:參數(shù)
參數(shù)取值范圍:
·inside:在BOX模型內(nèi)部顯示
·outside:在BOX模型外部顯示
這里又出現(xiàn)了一個(gè)新的概念:BOX模型。BOX是指一種容器,包含了應(yīng)用樣式規(guī)則的對(duì)象,具體介紹將在后文中給出。
使用無(wú)序列表:即UL
看一個(gè)最簡(jiǎn)單的例子:
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
這是一個(gè)未加修飾的縱向列表

1:設(shè)置列表的邊界
#base { border: 1px solid #000; margin: 2em; width: 10em; padding: 5px; }
html中這樣寫,就會(huì)呈現(xiàn)一個(gè)帶邊框的無(wú)序列表
<div id="base">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</div>

2:設(shè)定列表的圖像可以設(shè)定列表的樣式為左邊帶一個(gè)圖像,
樣式如下:
ul { list-style-type: disc; list-style-image: url(bullet.gif); list-style-position: inside; }
disc表示實(shí)心的圓,
list-style-image表示列表用到的小圖像,如果這個(gè)圖像的url不正確時(shí),disc才會(huì)起作用,inside表示列表是在區(qū)塊內(nèi)部的。

3:如何在段落中使用列表樣式如下:
#inline-list {
border: 1px solid #000; margin: 2em; width: 80%; padding: 5px; font-family: Verdana, sans-serif;
}
#inline-list p { display: inline; }
#inline-list ul, #inline-list li {
display: inline; margin: 0; padding: 0; color: #339; font-weight: bold;
}
4:水平導(dǎo)航
#h-contain {
padding: 5px; border: 1px solid #000; margin-bottom: 25px;
}
#pipe ul {
margin-left: 0; padding-left: 0; display: inline;
}
#pipe ul li {
margin-left: 0; padding: 3px 15px; border-left: 1px solid #000; list-style: none; display: inline;
}
#pipe ul li.first {
margin-left: 0; border-left: none; list-style: none; display: inline;
}
#h-contain定一個(gè)一個(gè)邊界為1的區(qū)塊,水平導(dǎo)航用的也是inline方式,
li.first定義第一個(gè)列表元素沒(méi)有左邊那個(gè)象素為1的border。

下面的樣式是tab方式的水平導(dǎo)航:
#tabs ul {
margin-left: 0; padding-left: 0; display: inline;
}
#tabs ul li {
margin-left: 0; margin-bottom: 0; padding: 2px 15px 5px; border: 1px solid #000; list-style: none; display: inline;
}
#tabs ul li.here {
border-bottom: 1px solid #ffc; list-style: none; display: inline;
}
li的class如果為here,則是選中的


強(qiáng)強(qiáng) 2013-03-12 17:51 發(fā)表評(píng)論
]]>
js 方式單擊ThickBox彈出窗口http://www.aygfsteel.com/lyjjq/articles/391550.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Sun, 18 Nov 2012 12:33:00 GMThttp://www.aygfsteel.com/lyjjq/articles/391550.htmlhttp://www.aygfsteel.com/lyjjq/comments/391550.htmlhttp://www.aygfsteel.com/lyjjq/articles/391550.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/391550.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/391550.htmlThickBox是一個(gè)強(qiáng)大的jQuery彈出窗口插件,一般的用法是在鏈接中,如:

Html代碼

  1. <a href="SearchWin.do?TB_iframe=true&height=380&width=480&modal=true" title="查詢企業(yè)" class="thickbox" >
  2. <img src="../images/search.png" border="0"/>
  3. </a>
<a  href="SearchWin.do?TB_iframe=true&height=380&width=480&modal=true" title="查詢企業(yè)" class="thickbox" >
<img src="../images/search.png" border="0"/>
</a>

指定a標(biāo)簽的class屬性為thickbox即可。這里會(huì)彈出一個(gè)模態(tài)窗口,并且是在iframe中彈出,這樣在彈出窗口中還可以執(zhí)行js代碼。  
有的時(shí)候在按鈕單擊的時(shí)候也需要彈出窗口,那么可以這樣做:  

Js代碼

  1. tb_show('標(biāo)題','StandDelay.do?booking='+t.title+'TB_iframe=true&height=150&width=400',false); 
tb_show('標(biāo)題','StandDelay.do?booking='+t.title+'TB_iframe=true&height=150&width=400',false);

來(lái)進(jìn)行彈出框口。在窗口中可以通過(guò)  

Js代碼

  1. self.parent.tb_remove(); 
 self.parent.tb_remove();

來(lái)關(guān)閉窗口,也可以通過(guò)以下代碼刷新父窗口的內(nèi)容:  

Js代碼

  1. self.parent.window.location.reload(); 


強(qiáng)強(qiáng) 2012-11-18 20:33 發(fā)表評(píng)論
]]>
使用js計(jì)算Date,非常幫,我也是轉(zhuǎn)摘的,非原創(chuàng)http://www.aygfsteel.com/lyjjq/articles/390486.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Tue, 30 Oct 2012 16:27:00 GMThttp://www.aygfsteel.com/lyjjq/articles/390486.htmlhttp://www.aygfsteel.com/lyjjq/comments/390486.htmlhttp://www.aygfsteel.com/lyjjq/articles/390486.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/390486.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/390486.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="    <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>日期計(jì)算</title>
 <script src="./jquery1.6.2.js" type="text/javascript"></script>
 <style>
     .error{color:red}
 </style>
 <script type="text/javascript">
   
     var intervalID = 0;
     function calculate(inputTime){
   
   var now = new Date();
   var t = new Date(inputTime);
   var past = (inputTime < now.getTime()) ? 1 : 0; //輸入的時(shí)間過(guò)去了就是1,否則為0
   var difference = 0; //差值
   //下面的差值減去八個(gè)小時(shí),是因?yàn)閚ew Date(0)是"Thu Jan 1 08:00:00 UTC+0800 1970",從八點(diǎn)開(kāi)始算的
   if(past) difference = new Date(now.getTime() - inputTime - 8 * 3600 * 1000);
   else difference = new Date(inputTime - now.getTime() - 8 * 3600 * 1000);

   //計(jì)算過(guò)去的天數(shù)、小時(shí)、分鐘和秒。天數(shù)要自己算,其它的get就行了
   var dDays = parseInt(difference.getTime() / 3600 / 24 /1000);
   var dHours = difference.getHours();
   var dMinutes =difference.getMinutes();
   var dSeconds = difference.getSeconds();
   
   $("#output").html([
    "現(xiàn)在時(shí)間是:<font color='blue'>", now.toLocaleString(),"</font>,","<br />",
    "<font color='blue'>", t.toLocaleString(),"</font>",
    ["還要", "已經(jīng)過(guò)去了"][past],
    "<font color='blue'>",dDays, "天", dHours, "小時(shí)", dMinutes, "分鐘", dSeconds, "秒","</font>",
    ["才到", ""][past]
   ].join(""));//用join方法將上面的數(shù)組連接起來(lái)
     }

     function btn_calculate(){
   
   clearInterval(intervalID);
   $("#error").className = null;
   
   var t = new Date($("#t").val());
   
   if(t.getTime().toString() == "NaN"){  //如果輸入的時(shí)間不對(duì),則將提示字符設(shè)置為error,即紅色
    $("#error").className = "error";
    $("#t").select();
    return false;
   }
   
   intervalID = setInterval("calculate(" + t.getTime() + ")", 1000);  //設(shè)置定時(shí)器,每秒鐘執(zhí)行一次calculate函數(shù)
   return false;
     }
 </script>
    </head>

    <body>
 <form onsubmit="return btn_calculate()">
     <div><span id="error">請(qǐng)輸入要計(jì)算的時(shí)間(格式:2010/02/01 23:07,省略時(shí)分秒則是00:00:00):</span>
  <input id="t" value="2010/02/01 23:07" /> <input type="submit" value="計(jì)算時(shí)間">
     </div><br />
     <div id="output"></div><!--輸出區(qū)域-->

    </body>
</html>



強(qiáng)強(qiáng) 2012-10-31 00:27 發(fā)表評(píng)論
]]>
flash中ExternalInterface不會(huì)造成方法覆蓋http://www.aygfsteel.com/lyjjq/articles/375312.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Thu, 19 Apr 2012 14:52:00 GMThttp://www.aygfsteel.com/lyjjq/articles/375312.htmlhttp://www.aygfsteel.com/lyjjq/comments/375312.htmlhttp://www.aygfsteel.com/lyjjq/articles/375312.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/375312.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/375312.html在JavaScript與Flash的通信一文中我介紹了利用ExternalInterface來(lái)實(shí)現(xiàn)的JS與AS雙向通信,有朋友跟我提出疑問(wèn)如果AS或者JS中都定義了同名函數(shù),那么會(huì)造成方法覆蓋嗎?這的確是個(gè)需要考慮的問(wèn)題,通過(guò)測(cè)試證明,即使出現(xiàn)了同名方法的定義,它們也是相互獨(dú)立的,不會(huì)造成方法覆蓋。

  一、AS調(diào)用JS方法時(shí)出現(xiàn)同名方法(查看實(shí)例)

 
    AS代碼如下:
   
    import flash.external.*;
    var v =ExternalInterface.available;
    t_btn.onRelease = function (){
        //調(diào)用JS函數(shù)
        var s = ExternalInterface.call("say","JS函數(shù)調(diào)用成功!")
        //調(diào)用AS本地函數(shù)
        s +=say("\n本地函數(shù)調(diào)用成功!");
        r_txt.text = s;
    }
    //AS本地函數(shù)
    function say(s){
        return s;
    }
  
    HTML代碼:
   //定義一個(gè)JS函數(shù)
   function say(txt){
        return txt;
    }

 可以看到在JS中定義了一個(gè)say方法供AS調(diào)用,現(xiàn)在我們?cè)贏S中定義了一個(gè)同名的say方法來(lái)驗(yàn)證它們是否會(huì)出現(xiàn)覆蓋。結(jié)果證明它們不會(huì)覆蓋,都工作得很好。(PS:不錯(cuò)~)


二、JS調(diào)用AS方法時(shí)出現(xiàn)同名方法(查看實(shí)例)


  AS代碼如下://導(dǎo)入包
        import flash.external.*;
        //提供JS訪問(wèn)的函數(shù)名
        var _method:String = "say";
        //指定本地函數(shù)中this變量的作用域,可設(shè)置為null留空
        var e_area:Object =null;
        //AS內(nèi)部函數(shù)名
        var method:Function = say;
        //將函數(shù)注冊(cè)到容器列表
        var wasSuccessful:Boolean = ExternalInterface.addCallback(_method, e_area, method);
        //查看注冊(cè)是否成功
        if(wasSuccessful){
            result_txt.text = "函數(shù)注冊(cè)成功";
        }
        //本地的函數(shù)
        function say(txt:String) {
            result_txt.text = txt;
        }

    HTML代碼如下:
 <div>
  <form>
   <input type="button" onclick="callExternalInterface()" value="JS調(diào)用AS方法" />
  </form>
  <script>
   function callExternalInterface() {
    thisMovie("demo").say("Hello,World");
   }
   //瀏覽器兼容訪問(wèn)DOM
   function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1)
    {
     return window[movieName]
    }else{
     return document[movieName]
    }
   }
   //定義一個(gè)JS本地函數(shù)
   function say(s){
    alert(s);
   }
  </script>
 </div>


  可以看到在AS中定義了一個(gè)say方法供JS調(diào)用,現(xiàn)在我們?cè)贘S中定義了一個(gè)同名的say方法來(lái)驗(yàn)證它們是否會(huì)出現(xiàn)覆蓋。結(jié)果證明它們不會(huì)覆蓋,都工作得很好。(PS:也不錯(cuò)~)


  通過(guò)上面的兩個(gè)例子我們可以得出結(jié)論在使用ExternalInterface時(shí)即使定義了同名方法,也不會(huì)造成方法覆蓋,你大可放心使用



強(qiáng)強(qiáng) 2012-04-19 22:52 發(fā)表評(píng)論
]]>
JS選中selecthttp://www.aygfsteel.com/lyjjq/articles/370147.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Thu, 16 Feb 2012 15:27:00 GMThttp://www.aygfsteel.com/lyjjq/articles/370147.htmlhttp://www.aygfsteel.com/lyjjq/comments/370147.htmlhttp://www.aygfsteel.com/lyjjq/articles/370147.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/370147.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/370147.html 




1.判斷select選項(xiàng)中
是否存在Value="paraValue"的Item
2.向select選項(xiàng)中 加入一個(gè)Item
3.從select選項(xiàng)中
刪除一個(gè)Item
4.修改select選項(xiàng)中
value="paraValue"的text為"paraText"
5.設(shè)置select中text="paraText"的第一個(gè)Item為選中
6.設(shè)置select中value="paraValue"的Item為選中
7.得到select的當(dāng)前選中項(xiàng)的value
8.得到select的當(dāng)前選中項(xiàng)的text
9.得到select的當(dāng)前選中項(xiàng)的Index
10.清空select的項(xiàng)
-------------------------------------------
//1.判斷select選項(xiàng)中
是否存在Value="paraValue"的Item
function
jsSelectIsExitItem(objSelect,objItemValue)
{
    var isExit =
false;
    for(var i=0;i<objSelect.options.length;i++)
    {
       
if(objSelect.options[i].value == objItemValue)
        {
           
isExit = true;
            break;
        }
    }     
    return
isExit;
}


//2.向select選項(xiàng)中 加入一個(gè)Item
function
jsAddItemToSelect(objSelect,objItemText,objItemValue)
{
   
//判斷是否存在
    if(jsSelectIsExitItem(objSelect,objItemValue))
   
{
        alert("該Item的Value值已經(jīng)存在");
    }
    else
    {
       
var varItem = new Option(objItemText,objItemValue);
//     
objSelect.options[objSelect.options.length] = varItem;
       
objSelect.options.add(varItem);
        alert("成功加入");
    }   
}


//3.從select選項(xiàng)中 刪除一個(gè)Item
function
jsRemoveItemFromSelect(objSelect,objItemValue)
{
    //判斷是否存在
   
if(jsSelectIsExitItem(objSelect,objItemValue))
    {
        for(var
i=0;i<objSelect.options.length;i++)
        {
           
if(objSelect.options[i].value == objItemValue)
           
{
                objSelect.options.remove(i);
               
break;
            }
        }       
       
alert("成功刪除");           
    }
    else
    {
       
alert("該select中 不存在該項(xiàng)");
    }   
}


//4.修改select選項(xiàng)中
value="paraValue"的text為"paraText"
function
jsUpdateItemToSelect(objSelect,objItemText,objItemValue)
{
   
//判斷是否存在
    if(jsSelectIsExitItem(objSelect,objItemValue))
   
{
        for(var i=0;i<objSelect.options.length;i++)
       
{
            if(objSelect.options[i].value == objItemValue)
           
{
                objSelect.options[i].text = objItemText;
               
break;
            }
        }       
       
alert("成功修改");           
    }
    else
    {
       
alert("該select中 不存在該項(xiàng)");
    }   
}
       

//5.設(shè)置select中text="paraText"的第一個(gè)Item為選中
function
jsSelectItemByValue(objSelect,objItemText)
{   
    //判斷是否存在
    var
isExit = false;
    for(var i=0;i<objSelect.options.length;i++)
   
{
        if(objSelect.options[i].text == objItemText)
       
{
            objSelect.options[i].selected = true;
            isExit =
true;
            break;
        }
    }     
    //Show出結(jié)果
   
if(isExit)
    {
        alert("成功選中");           
    }
   
else
    {
        alert("該select中 不存在該項(xiàng)");
    }   
}


//6.設(shè)置select中value="paraValue"的Item為選中
//document.all.objSelect.value
= objItemValue;


//7.得到select的當(dāng)前選中項(xiàng)的value
//var currSelectValue =
document.all.objSelect.value;


//8.得到select的當(dāng)前選中項(xiàng)的text
//var currSelectText =
document.all.objSelect.options[document.all.objSelect.selectedIndex].text;


//9.得到select的當(dāng)前選中項(xiàng)的Index
//var currSelectIndex =
document.all.objSelect.selectedIndex;


//10.清空select的項(xiàng)
//
document.all.objSelect.options.length = 0;



強(qiáng)強(qiáng) 2012-02-16 23:27 發(fā)表評(píng)論
]]>
JQuery 事件,屬性,綁定http://www.aygfsteel.com/lyjjq/articles/368759.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Thu, 19 Jan 2012 07:30:00 GMThttp://www.aygfsteel.com/lyjjq/articles/368759.htmlhttp://www.aygfsteel.com/lyjjq/comments/368759.htmlhttp://www.aygfsteel.com/lyjjq/articles/368759.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/368759.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/368759.html.addClass() 向取得的元素添加class即類,而該元素原來(lái)的類不會(huì)被去掉,

如果想添加別的屬性用attr()----attr({'id':'value'})  相對(duì)的是:removeAttr('id');

******************************************************************************************************************************************************************

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html xmlns="http://www.w3.org/1999/xhtml">
< head>
< meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
< title>無(wú)標(biāo)題文檔</title>
< link rel="stylesheet" type="text/css" href="Untitled-2.css" />
< script type="text/javascript" src="jquery-1.6.2.js"></script>
< script type="text/javascript">
$(document).ready(function(){
//通過(guò)選擇符選取元素
$('#selected-plays > li').addClass('horizontal');
$('#selected-plays li:not(.horizontal)').addClass('sub-level');
$('a[href^=mailto]').addClass('mailto');
$("a[href$='.pdf']").addClass('pdflink');
$("a[href^='http'][href*='henry']").addClass('henrylink');
$("tr:even").addClass('alt');//$("tr:odd").addClass('alt');

//通過(guò)連綴來(lái)取得元素
$("td:contains('Tragedy')").addClass('cell01');
$("td:contains('Henry')").parent().children().addClass('cell02');
$("td:contains('Tragedy')").next().andSelf().addClass('cell03');
$("td:contains('Comedy')").nextAll().andSelf().addClass('cell04');
$("td:contains('Comedy')").prev().andSelf().addClass('cell05');
$("td:contains('Macbeth')").prevAll().andSelf().addClass('cell06');

//通過(guò)連綴取得元素
$("td:contains('Henry')")//取的所有包含‘Henry’的單元格
.parent()//取得它的父元素
.find("td:eq(1)")//取得第二個(gè)td元素
.addClass('highlight')//為取得的td元素添加highlight類
.end()//恢復(fù)到所有包含'Henry'的父元素
.find("td:eq(2)")//取得第三個(gè)td元素
.addClass('highlight');//為該元素添加highlight類
 
//事件
$('h3').nextAll().addClass('childendiv');
$('#switcher-large').bind('click',function(){//為div添加樣式
  $('#switcher-large').removeClass('button');//移除class
  $(this).addClass('chapter');//this指的是綁定事件的對(duì)象
  });

//事件綁定的簡(jiǎn)寫
/*
$('#switcher-large').click(function(){//為div添加樣式
  $('#switcher-large').removeClass('button');//移除class
  $(this).addClass('chapter');//this指的是綁定事件的對(duì)象
  });*/
 
 
//復(fù)合事件:點(diǎn)擊第一次時(shí)執(zhí)行toggle里面的第一個(gè)函數(shù),點(diǎn)擊第二才是執(zhí)行第二個(gè)函數(shù)……如果都執(zhí)行完就再循環(huán)
$('h3').toggle(
  function(){
  $('.button').addClass('hidden');
  },
  function(){
   $('.button').removeClass('hidden');
   });

//hover()跟toggle一樣,也可以接受都多個(gè)函數(shù),第一個(gè)函數(shù)在鼠標(biāo)進(jìn)入元素是執(zhí)行,第二個(gè)函數(shù)會(huì)在鼠標(biāo)離開(kāi)元素時(shí)執(zhí)行
$('.button').hover(
  function(){
   $(this).addClass('hover');
   },
   function(){
   $(this).removeClass('hover');
   })

//通過(guò)事件對(duì)象來(lái)改變時(shí)間旅程
$('.divparent').click(function(event){
  if(event.target==this){
   $('.divparent').children().toggleClass('hidden')  
   }
  })
 
//事件冒泡:點(diǎn)擊<td>中的div時(shí),也會(huì)觸發(fā)到<table>外面<div>事件
/*$
('td').addClass('td');
$('.but').addClass('but');
$('.switcher').click(function(){
  $('.switcher .but').toggleClass('hidden');
  });
*/

//事件目標(biāo):可以有效的解決事件冒泡;
$('.switcher').click(function(event){
  if(event.target==this){
   $('.switcher .but').toggleClass('hidden');
   }
  });
 
/*$('.switcher').click(function(event){
  if($(event.target).is('.but')){
   $('body').removeClass();
   if(event.target.id=='switcher-nar'){
    $('body').addClass('large');
    }
    else if(event.target.id=='switcher-lar'){
     $('body').addClass('large');
     }
     $('.switcher .but').removeClass('selected');
     $(event.target).addClass('selected');
     event.stopPropagation();
   }
  });*/
 
//移除事件:
/*
$('.but').click(function(){
  $('.switcher').unbind();//移除事件
  });*/
 
//只綁定一次就解除用one()
$('.but1').one('click',function(){
  $('.but1').addClass('hidden');
  });

});



強(qiáng)強(qiáng) 2012-01-19 15:30 發(fā)表評(píng)論
]]>
ThinkPhp標(biāo)簽庫(kù)http://www.aygfsteel.com/lyjjq/articles/362377.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Mon, 31 Oct 2011 07:15:00 GMThttp://www.aygfsteel.com/lyjjq/articles/362377.htmlhttp://www.aygfsteel.com/lyjjq/comments/362377.htmlhttp://www.aygfsteel.com/lyjjq/articles/362377.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/362377.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/362377.html告:在使用下列所說(shuō)的任何標(biāo)簽庫(kù)都需要
HTML第一行加入 <tarlib name=”cx,html” />
如果想單獨(dú)引入cx標(biāo)簽庫(kù)就直接寫成<tarlib name=”cx” />
如果單獨(dú)引入html標(biāo)簽庫(kù)就直接寫成<tarlib name=”html” />
原則上來(lái)講所有的標(biāo)簽的屬性是可以不增加的(因?yàn)閠p并為進(jìn)行強(qiáng)制驗(yàn)證^_^),不過(guò)為了你的正常使用,請(qǐng)?jiān)谑褂玫臅r(shí)候按照需要進(jìn)行添加
首先我們來(lái)說(shuō)html標(biāo)簽庫(kù)的信息
Editor標(biāo)簽
<html:editor id=”editory” name=”remarke” type=”FCKeditor” content=”” />
屬性
        Id 屬性
                編輯器的id值,
                如果并未填寫改屬性,則會(huì)默認(rèn)為_(kāi)editor
        Name 屬性 必須的
                編輯器的 name值
                如果未填寫,默認(rèn)為空
        Width 屬性 
                編輯器的寬度
                如果未填寫,默認(rèn)為100%
        Height 屬性
                編輯器的高度
                如果未填寫默認(rèn)為320px
        Content 屬性
                編輯器的內(nèi)容的初始化值
                如果未填寫,則為空
        Type 屬性
                編輯器的類型 默認(rèn)情況下支持
Fckeditor  eWebEditor  NETEASE  UBB
如果填寫的編輯器類型不存在,則會(huì)默認(rèn)為 TextArea標(biāo)簽
指定Fckeditor 時(shí),文件存放路徑必須為 /Public/Js/FCKeditor/
指定eWebEditor 時(shí),文件存放路徑必須為/Public/Js/eWebEditor/
指定NETEASE 時(shí),文件存放路徑必須為/Public/Js/HtmlEditor/
指定UBB時(shí),文件存放路徑必須為/Public/Js/
imageBtn標(biāo)簽
        <html:imageBtn id=" " name=" " type=" " value=" " click=" " style=" " />
        屬性:
                Id屬性
                        input的id值
                Name屬性
                        input的name值
                Type 屬性
                        input標(biāo)記的類型
                        如果未填寫 則默認(rèn)為 button
                Value 屬性
                        input標(biāo)記的Value值
                click 屬性
                        input 的click執(zhí)行內(nèi)容,可以為js語(yǔ)句塊,也可以為js函數(shù)
                style 屬性
                        input標(biāo)記外面生成div的樣式
imgLink標(biāo)簽
<html:imgLink id=" " name=" " alt=" " click=" " style=" " type=" " value=" " />
提示:
        這個(gè)標(biāo)記增加了鼠標(biāo)移上和移除的濾鏡效果,推薦使用,不過(guò)內(nèi)部實(shí)現(xiàn)是有問(wèn)題的,如果需要使用的同志,請(qǐng)修改一下TagLibHtml.class.php 125行
$parseStr   = '<span class="'.$style.'" ><input title="'.$alt.'" type="'.$type.'" id="'.$id.'"  name="'.$name.'" onmouseover="this.style.filter=/'alpha(opacity=100)/'" onmouseout="this.style.filter=/'alpha(opacity=80)/'" onclick="'.$click.'" align="absmiddle" class="'.$name.' value="'.$value.'"></span>';
屬性:
        id屬性
                input的id值
        name屬性
                input的name值
        alt屬性
                input的title值
        style屬性
                input標(biāo)記外面生成的span的樣式
        click屬性
                input的click執(zhí)行內(nèi)容,可以為js語(yǔ)句塊,也可以為js函數(shù)
        type屬性
                input屬性的類別,如果不輸入則默認(rèn)為button
        value屬性
                input 的value的值,不過(guò)在源代碼里面并未使用
select標(biāo)記
<html:select options=" " selected=" " id=" " name=" " values=" " output=" " multiple=" " size=" " first=" " style=" " dblclick=" " change=" " />
屬性:
        id屬性
                select的id值
        name屬性
                select的name值
        dblclick屬性
                select 雙擊事件調(diào)用的js
        change屬性
                select value值改變調(diào)用的js
        multiple屬性
                select 是否以可以選擇多項(xiàng) 值不固定,任意值均可
        style屬性
                select 的樣式
        size屬性
                select 的行數(shù)
        first屬性
                select 的第一個(gè)值,比如 請(qǐng)選擇您的學(xué)歷
        options屬性
                select的項(xiàng),為php的有鍵的數(shù)組,如果沒(méi)有鍵的數(shù)組請(qǐng)使用values屬性
                當(dāng)兩個(gè)屬性同時(shí)存在時(shí),以options為優(yōu)先
                value的值為$key
        values屬性
                select的項(xiàng),為php無(wú)鍵的數(shù)組,當(dāng)兩個(gè)屬性同時(shí)存在時(shí),以options為優(yōu)先
                value的值為數(shù)組的值
        selected屬性
                select 默認(rèn)的選中項(xiàng)
                當(dāng)使用options屬時(shí),selected屬性的內(nèi)容與$key進(jìn)行匹配,如果使用values屬性
                則與內(nèi)容進(jìn)行匹配
        output屬性
                select option項(xiàng)目的結(jié)尾串,比如 
                <option value=”1”>小學(xué)學(xué)歷</option>
                <option value=”2”>中學(xué)學(xué)歷</option>
                <option value=”3”>大學(xué)學(xué)歷</option>
                這里的情況,我們就可以直接設(shè)置output為 學(xué)歷
checkbox標(biāo)簽
        <html:checkbox checkboxes=" " checked=" " name=" " separator=" " />
提示:
checkboxes="" 請(qǐng)注意看這個(gè)屬性 并不是checkboxs 在s的前面多了一個(gè)e
我想應(yīng)該是官方手誤吧,如果你愿意,請(qǐng)修改源碼,或者說(shuō)在使用的時(shí)候加上e
屬性:
        name屬性
                checkbox屬性的name值,無(wú)論你輸入什么,系統(tǒng)會(huì)默認(rèn)增加[]
        checkboxes
                checkbox組,是php的有鍵數(shù)組(必須為有鍵數(shù)組),$key為checkbox項(xiàng)的value
                $value 為checkbox后面帶的說(shuō)明
        checked
                這里可以為數(shù)組,也可以為單個(gè)字符串
                如果為字符串,則與$key進(jìn)行匹配 判斷是否選中
                如果為數(shù)組,則匹配是否包含這個(gè)$key 判斷是否選中
        separator
                分隔符,當(dāng)一個(gè)checkbox項(xiàng)結(jié)束后的分隔符
radio標(biāo)簽
        <html:radio radios=" " checked=" " checked=" " separator=" " />
屬性
        radios
                radio組是php的有鍵數(shù)組(必須為有鍵數(shù)組),$key為radio項(xiàng)的value
                $value 為radio后面帶的說(shuō)明
        checked
                這里可以為數(shù)組,也可以為單個(gè)字符串
                如果為字符串,則與$key進(jìn)行匹配 判斷是否選中
        name屬性
                radio屬性的name值,無(wú)論你輸入什么,系統(tǒng)會(huì)默認(rèn)增加[]
        separator
                分隔符,當(dāng)一個(gè)radio項(xiàng)結(jié)束后的分隔符
link標(biāo)簽解析
* 格式: <html:link file="" type="" />
加載外部文件,type為文件類型(可選,建議填上),JS和CSS


強(qiáng)強(qiáng) 2011-10-31 15:15 發(fā)表評(píng)論
]]>
json數(shù)據(jù)格式例子http://www.aygfsteel.com/lyjjq/articles/355501.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Mon, 01 Aug 2011 08:50:00 GMThttp://www.aygfsteel.com/lyjjq/articles/355501.htmlhttp://www.aygfsteel.com/lyjjq/comments/355501.htmlhttp://www.aygfsteel.com/lyjjq/articles/355501.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/355501.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/355501.html    function handleJson(){
        var j={"name":"Michael","address":{"city":"Beijing","street":"Chaoyang Road","postcode":100025},"person":[{"city":"Beijing"},{"city":"Chaoyang Road"},{"city":100025}]};
        document.write(j.name);
        document.write(j.address.city);
        document.write(j.person[1].city);
    }
    handleJson();
</script>

強(qiáng)強(qiáng) 2011-08-01 16:50 發(fā)表評(píng)論
]]>
Javascript 操作select控件大全(新增、修改、刪除、選中、清空、判斷存在等)http://www.aygfsteel.com/lyjjq/articles/346898.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Wed, 23 Mar 2011 16:02:00 GMThttp://www.aygfsteel.com/lyjjq/articles/346898.htmlhttp://www.aygfsteel.com/lyjjq/comments/346898.htmlhttp://www.aygfsteel.com/lyjjq/articles/346898.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/346898.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/346898.html 
Javascript 操作select是表單中常見(jiàn)的一種,今天刪除多個(gè)select值的時(shí)候出現(xiàn)了問(wèn)題,搞了半天原來(lái)是索引引起的(即刪除的時(shí)候要從索引大的開(kāi)始刪,然后再刪除索引小的,否則刪除了索引小的后索引大的索引就變化了,再刪除時(shí)就會(huì)出現(xiàn)問(wèn)題--問(wèn)題的關(guān)鍵是for循環(huán)是要從大到小,而不是常規(guī)的從0到length)

// 4.刪除select中選中的項(xiàng)   
function jsRemoveSelectedItemFromSelect(objSelect) {       
     var length = objSelect.options.length - 1;   
     for(var i = length; i >= 0; i--){   
         if(objSelect[i].selected == true){   
             objSelect.options[i] = null;   
         }   
     }   
}     

1判斷select選項(xiàng)中 是否存在Value="paraValue"的Item
2向select選項(xiàng)中 加入一個(gè)Item
3從select選項(xiàng)中 刪除一個(gè)Item
4刪除select中選中的項(xiàng)
5修改select選項(xiàng)中 value="paraValue"的text為"paraText"
6設(shè)置select中text="paraText"的第一個(gè)Item為選中
7設(shè)置select中value="paraValue"的Item為選中
8得到select的當(dāng)前選中項(xiàng)的value
9得到select的當(dāng)前選中項(xiàng)的text
10得到select的當(dāng)前選中項(xiàng)的Index
11清空select的項(xiàng)

======================================================================

動(dòng)態(tài)刪除select中的所有options:
function deleteAllOptions(sel){
sel.options.length=0;
}
動(dòng)態(tài)刪除select中的某一項(xiàng)option:
function deleteOption(sel,indx){
sel.options.remove(indx);
}
動(dòng)態(tài)添加select中的項(xiàng)option:
function addOption(sel,text,value){
sel.options.add(new Option(text,value));
}
上面在IE和FireFox都能測(cè)試成功,希望以后可以用上。

===========================================

js 代碼
// 1.判斷select選項(xiàng)中 是否存在Value="paraValue"的Item       
function jsSelectIsExitItem(objSelect, objItemValue) {       
     var isExit = false;       
     for (var i = 0; i < objSelect.options.length; i++) {       
         if (objSelect.options[i].value == objItemValue) {       
             isExit = true;       
             break;       
         }       
     }       
     return isExit;       
}        
  
// 2.向select選項(xiàng)中 加入一個(gè)Item       
function jsAddItemToSelect(objSelect, objItemText, objItemValue) {       
     //判斷是否存在       
     if (jsSelectIsExitItem(objSelect, objItemValue)) {       
         alert("該Item的Value值已經(jīng)存在");       
     } else {       
         var varItem = new Option(objItemText, objItemValue);     
         objSelect.options.add(varItem);    
         alert("成功加入");    
     }       
}       
  
// 3.從select選項(xiàng)中 刪除一個(gè)Item       
function jsRemoveItemFromSelect(objSelect, objItemValue) {       
     //判斷是否存在       
     if (jsSelectIsExitItem(objSelect, objItemValue)) {       
         for (var i = 0; i < objSelect.options.length; i++) {       
             if (objSelect.options[i].value == objItemValue) {       
                 objSelect.options.remove(i);       
                 break;       
             }       
         }       
         alert("成功刪除");       
     } else {       
         alert("該select中 不存在該項(xiàng)");       
     }       
}   
  
  
// 4.刪除select中選中的項(xiàng)   
function jsRemoveSelectedItemFromSelect(objSelect) {       
     var length = objSelect.options.length - 1;   
     for(var i = length; i >= 0; i--){   
         if(objSelect[i].selected == true){   
             objSelect.options[i] = null;   
         }   
     }   
}     
  
// 5.修改select選項(xiàng)中 value="paraValue"的text為"paraText"       
function jsUpdateItemToSelect(objSelect, objItemText, objItemValue) {       
     //判斷是否存在       
     if (jsSelectIsExitItem(objSelect, objItemValue)) {       
         for (var i = 0; i < objSelect.options.length; i++) {       
             if (objSelect.options[i].value == objItemValue) {       
                 objSelect.options[i].text = objItemText;       
                 break;       
             }       
         }       
         alert("成功修改");       
     } else {       
         alert("該select中 不存在該項(xiàng)");       
     }       
}       
  
// 6.設(shè)置select中text="paraText"的第一個(gè)Item為選中       
function jsSelectItemByValue(objSelect, objItemText) {           
     //判斷是否存在       
     var isExit = false;       
     for (var i = 0; i < objSelect.options.length; i++) {       
         if (objSelect.options[i].text == objItemText) {       
             objSelect.options[i].selected = true;       
             isExit = true;       
             break;       
         }       
     }             
     //Show出結(jié)果       
     if (isExit) {       
         alert("成功選中");       
     } else {       
         alert("該select中 不存在該項(xiàng)");       
     }       
}       
  
// 7.設(shè)置select中value="paraValue"的Item為選中   
objSelect.value = objItemValue;   
      
// 8.得到select的當(dāng)前選中項(xiàng)的value   
var currSelectValue = objSelect.value;   
      
// 9.得到select的當(dāng)前選中項(xiàng)的text   
var currSelectText = objSelect.options[document.all.objSelect.selectedIndex].text;   
      
// 10.得到select的當(dāng)前選中項(xiàng)的Index   
var currSelectIndex = objSelect.selectedIndex;   
      
// 11.清空select的項(xiàng)   
objSelect.options.length = 0;  


整個(gè)實(shí)例的完整代碼如下:

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>javascript select options text value</title>
<meta name="keywords" content="javascript select options text value add modify delete set">
<meta name="description" content="javascript select options text value add modify delete set">
<script language="javascript">
<!--
// Author: i@lxl.cn
// Modify: i@cnlei.com
function watch_ini(){ // 初始
for(var i=0; i<arguments.length; i++){
   var oOption=new Option(arguments[i],arguments[i]);
   document.getElementById("MySelect")[i]=oOption;
}
}
function watch_add(f){ // 增加
   var oOption=new Option(f.word.value,f.word.value);
   f.keywords[f.keywords.length]=oOption;
}
function watch_sel(f){ // 編輯
f.word.value = f.keywords[f.keywords.selectedIndex].text;
}
function watch_mod(f){ // 修改
f.keywords[f.keywords.selectedIndex].text = f.word.value;
}
function watch_del(f){ // 刪除
f.keywords.remove(f.keywords.selectedIndex);
}
function watch_set(f){ // 保存
var set = "";
for(var i=0; i<f.keywords.length; i++){
set += f.keywords[i].text + ";";
}
confirm(set);
}
//-->
</script>
</head>
<body>
<form name="watch" method="post" action="">
<select id="MySelect" name="keywords" size="10" onchange="watch_sel(this.form)"></select><br>
<script language="javascript">
<!--
watch_ini("我","你","妳","他","她","它","爾"); // 初始關(guān)鍵詞
//-->
</script>
<input type="text" name="word" /><br />
<input type="button" value="增加" onclick="watch_add(this.form);" />
<input type="button" value="修改" onclick="watch_mod(this.form);" />
<input type="button" value="刪除" onclick="watch_del(this.form);" />
<input type="button" value="保存" onclick="watch_set(this.form);" />
</form>
</body>
</html>


強(qiáng)強(qiáng) 2011-03-24 00:02 發(fā)表評(píng)論
]]>
各種ajax 的json 數(shù)據(jù)的傳遞(jquery,prototype,thinkajax) http://www.aygfsteel.com/lyjjq/articles/346896.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Wed, 23 Mar 2011 15:37:00 GMThttp://www.aygfsteel.com/lyjjq/articles/346896.htmlhttp://www.aygfsteel.com/lyjjq/comments/346896.htmlhttp://www.aygfsteel.com/lyjjq/articles/346896.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/346896.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/346896.htmlfunction showRequest() {
  //alert('before submit!');   
 }
 function reloadCityArr(data){
  var targetSelect=document.getElementById("citySelect");
  clearField(targetSelect)
  for (var i = 0; i < data.length; i++) {   
   var opt = document.createElement("OPTION");
   opt.text=data[i].title;      
   opt.value=data[i].value;  
   targetSelect.add(opt);                           
        }

 }
 
 function clearField(targetSelect){
  
   var listlength=targetSelect.length;

   for (i=listlength-1;i>=0;i--)
         {targetSelect.remove(i);}

 }
//1.prototype方式
 function addChangeProvince(provinceId) {
     var url="__URL__/getCityMap/provinceId/"+provinceId;
   
     new Ajax.Request(url,{
        method: 'get',
        onComplete: function(transport){ 
        reloadCityArr(eval(transport.responseText));        
     }});
 }
//2.jquery
function addChangeProvince(provinceId) {
     var url="__URL__/getCityMap/provinceId/"+provinceId;   
     $.ajax({
         type: "POST",
         url: url,
         data: "name=John&location=Boston",
         dataType:"json",
         success: function(data){
           reloadCityArr(data);   
         
        
        }
     });
 }
//3.thinkajax
 function complete(data,status,info){
  if (status==1){
   reloadCityArr(data);
  }
 }
 function addChangeProvince(provinceId) {
     var url="__URL__/getCityMap/provinceId/"+provinceId;
     ThinkAjax.sendForm('form1',url,complete,'result');
 }



強(qiáng)強(qiáng) 2011-03-23 23:37 發(fā)表評(píng)論
]]>
關(guān)于Apache的AddDefaultCharset的問(wèn)題http://www.aygfsteel.com/lyjjq/articles/344008.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Thu, 10 Feb 2011 02:11:00 GMThttp://www.aygfsteel.com/lyjjq/articles/344008.htmlhttp://www.aygfsteel.com/lyjjq/comments/344008.htmlhttp://www.aygfsteel.com/lyjjq/articles/344008.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/344008.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/344008.html

上周飛龍新版上線的時(shí)候,出現(xiàn)了一個(gè)問(wèn)題由于原來(lái)的頁(yè)面是用的GBK編碼的。新版的面頁(yè)使用了utf-8編碼的。晚上部署的時(shí)候發(fā)現(xiàn)utf-8編碼的全部都成亂碼了。這個(gè)亂碼是因?yàn)闉g覽器用gbk解析utf-8的網(wǎng)頁(yè)的。手動(dòng)選擇一下用utf-8編碼就正常的了。剛開(kāi)始還以為是utf-8頁(yè)面的問(wèn)題。看html源碼。里面有utf-8的頭申明。看jsp里面也有的。為什么Apache就是不用utf-8發(fā)送給瀏覽器呢?
后來(lái)找到httpd.conf.發(fā)面里面的AddDefaultCharset設(shè)置的是

AddDefaultCharset=GBK

沒(méi)辦法先修改成UTF-8試試

AddDefaultCharset=UTF-8

這樣的話utf-8的頁(yè)面好了。可是gbk的又不行了。真是怪了。后來(lái)發(fā)現(xiàn)把這個(gè)設(shè)置成off就可以了。

AddDefaultCharset=off

一查Apache的參考手冊(cè),原來(lái)是這樣的。

AddDefaultCharset 指令

說(shuō)明 當(dāng)應(yīng)答內(nèi)容是text/plaintext/html時(shí),在HTTP應(yīng)答頭中加入的默認(rèn)字符集
語(yǔ)法 AddDefaultCharset On|Off|charset
默認(rèn)值 AddDefaultCharset Off
作用域 server config, virtual host, directory, .htaccess
覆蓋項(xiàng) FileInfo
狀態(tài) 核心(C)
模塊 core

當(dāng)且僅當(dāng)應(yīng)答內(nèi)容是text/plaintext/html時(shí),此指令將會(huì)在HTTP應(yīng)答頭中加入的默認(rèn)字符集。理論上這將覆蓋在文檔體中通過(guò)<meta>標(biāo)簽指定的字符集,但是實(shí)際的行為通常取決于用戶瀏覽器的設(shè)置。AddDefaultCharset Off 將會(huì)禁用此功能。AddDefaultCharset On 將啟用Apache內(nèi)部的默認(rèn)字符集iso-8859-1 。您也可以指定使用在IANA注冊(cè)過(guò)的字符集名字中的另外一個(gè)charset 。比如說(shuō):

AddDefaultCharset utf-8

AddDefaultCharset只 應(yīng)當(dāng)在如下情況下使用:所有文本資源都使用同一種確定的字符集,且分別標(biāo)記他們的字符集非常麻煩。一個(gè)這樣的例子是向包含動(dòng)態(tài)內(nèi)容的資源中添加字符集參數(shù) (比如先前遺留的CGI腳本),這樣可能會(huì)因?yàn)樵谳敵鲋邪脩籼峁┑臄?shù)據(jù)而導(dǎo)致跨站點(diǎn)腳本攻擊。但是請(qǐng)注意:更好的解決辦法是修改或刪除這些腳本,因?yàn)?設(shè)置了默認(rèn)的字符集以后將會(huì)使得瀏覽器的字符集自動(dòng)探測(cè)功能失效。

原來(lái)這個(gè)是給那種沒(méi)有申明編碼的頁(yè)面用的。如果你的站點(diǎn)只有一種編碼就可以使用這個(gè)指令,如果有兩種就不能用了。那就是還記得將所有的頁(yè)面都加上好合適的編碼頭申明。


強(qiáng)強(qiáng) 2011-02-10 10:11 發(fā)表評(píng)論
]]>
jquery 取input中各項(xiàng)值http://www.aygfsteel.com/lyjjq/articles/331221.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Mon, 06 Sep 2010 08:49:00 GMThttp://www.aygfsteel.com/lyjjq/articles/331221.htmlhttp://www.aygfsteel.com/lyjjq/comments/331221.htmlhttp://www.aygfsteel.com/lyjjq/articles/331221.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/331221.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/331221.html 

radio取值,checkbox取值,select取值,radio選中,checkbox選中,select選中,及其相關(guān)
獲取一組radio被選中項(xiàng)的值
var item = $('input[@name=items][@checked]').val();
獲取select被選中項(xiàng)的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二個(gè)元素為當(dāng)前選中值
$('#select_id')[0].selectedIndex = 1;
radio單選組的第二個(gè)元素為當(dāng)前選中值
$('input[@name=items]').get(1).checked = true;

獲取值:

文本框,文本區(qū)域:
     $("#txt").attr("value");
多選框checkbox:
     $("#checkbox_id").attr("value");
單選組radio:
     $("input[@type=radio][@checked]").val();
下拉框select:
     $('#sel').val();

控制表單元素:
文本框,文本區(qū)域:
     $("#txt").attr("value",'');//清空內(nèi)容
                $("#txt").attr("value",'11');//填充內(nèi)容

多選框checkbox:
     $("#chk1").attr("checked",'');//不打勾
                $("#chk2").attr("checked",true);//打勾
                if($("#chk1").attr('checked')==undefined) //判斷是否已經(jīng)打勾

單選組radio:  
     $("input[@type=radio]").attr("checked",'2');//設(shè)置value=2的項(xiàng)目為當(dāng)前選中項(xiàng)
下拉框select:
     $("#sel").attr("value",'-sel3');//設(shè)置value=-sel3的項(xiàng)目為當(dāng)前選中項(xiàng)
     $("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//添加下拉框的option
     $("#sel").empty();//清空下拉框
----------------------------------------------------------------------------------------------------

//遍歷option和添加、移除option
function changeShipMethod(shipping){
var len = $("select[@name=ISHIPTYPE] option").length
if(shipping.value != "CA"){
$("select[@name=ISHIPTYPE] option").each(function(){
if($(this).val() == 111){
$(this).remove();
}
});
}else{
$("<option value='111'>UPS Ground</option>").appendTo($("select[@name=ISHIPTYPE]"));
}
}

//取得下拉選單的選取值
$(#testSelect option:selected').text();
或$("#testSelect").find('option:selected').text();
或$("#testSelect").val();
//////////////////////////////////////////////////////////////////
記性不好的可以收藏下:
1,下拉框:
var cc1 = $(".formc select[@name='country'] option[@selected]").text(); //得到下拉菜單的選中項(xiàng)的文本(注意中間有空格)
var cc2 = $('.formc select[@name="country"]').val(); //得到下拉菜單的選中項(xiàng)的值
var cc3 = $('.formc select[@name="country"]').attr("id"); //得到下拉菜單的選中項(xiàng)的ID屬性值
$("#select").empty();//清空下拉框//$("#select").html('');
$("<option value='1'>1111</option>").appendTo("#select")//添加下拉框的option
稍微解釋一下:
1.select[@name='country'] option[@selected] 表示具有name 屬性,
并且該屬性值為'country' 的select元素 里面的具有selected 屬性的option 元素;
可以看出有@開(kāi)頭的就表示后面跟的是屬性。
2,單選框:
$("input[@type=radio][@checked]").val(); //得到單選框的選中項(xiàng)的值(注意中間沒(méi)有空格)
$("input[@type=radio][@value=2]").attr("checked",'checked'); //設(shè)置單選框value=2的為選中狀態(tài).(注意中間沒(méi)有空格)
3,復(fù)選框:
$("input[@type=checkbox][@checked]").val(); //得到復(fù)選框的選中的第一項(xiàng)的值
$("input[@type=checkbox][@checked]").each(function(){ //由于復(fù)選框一般選中的是多個(gè),所以可以循環(huán)輸出
alert($(this).val());
});
$("#chk1").attr("checked",'');//不打勾
$("#chk2").attr("checked",true);//打勾
if($("#chk1").attr('checked')==undefined){} //判斷是否已經(jīng)打勾

當(dāng)然jquery的選擇器是強(qiáng)大的. 還有很多方法.
<script src="jquery-1.2.1.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#selectTest").change(function()
{
//alert("Hello");
//alert($("#selectTest").attr("name"));
//$("a").attr("href","xx.html");
//window.location.href="xx.html";
//alert($("#selectTest").val());
alert($("#selectTest option[@selected]").text());
$("#selectTest").attr("value", "2");
});
});
</script>

<a href="#">aaass</a>
<!--下拉框-->
<select id="selectTest" name="selectTest">
<option value="1">11</option>
<option value="2">22</option>
<option value="3">33</option>
<option value="4">44</option>
<option value="5">55</option>
<option value="6">66</option>
</select>
jquery radio取值,checkbox取值,select取值,radio選中,checkbox選中,select選中,及其相關(guān)獲取一組radio被選中項(xiàng)的值
var item = $('input[@name=items][@checked]').val();
獲取select被選中項(xiàng)的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二個(gè)元素為當(dāng)前選中值
$('#select_id')[0].selectedIndex = 1;
radio單選組的第二個(gè)元素為當(dāng)前選中值
$('input[@name=items]').get(1).checked = true;
獲取值:
文本框,文本區(qū)域:$("#txt").attr("value");
多選框checkbox:$("#checkbox_id").attr("value");
單選組radio: $("input[@type=radio][@checked]").val();
下拉框select: $('#sel').val();
控制表單元素:
文本框,文本區(qū)域:$("#txt").attr("value",'');//清空內(nèi)容
$("#txt").attr("value",'11');//填充內(nèi)容
多選框checkbox: $("#chk1").attr("checked",'');//不打勾
$("#chk2").attr("checked",true);//打勾
if($("#chk1").attr('checked')==undefined) //判斷是否已經(jīng)打勾
單選組radio: $("input[@type=radio]").attr("checked",'2');//設(shè)置value=2的項(xiàng)目為當(dāng)前選中項(xiàng)
下拉框select: $("#sel").attr("value",'-sel3');//設(shè)置value=-sel3的項(xiàng)目為當(dāng)前選中項(xiàng)
$("<optionvalue='1'>1111</option><optionvalue='2'>2222</option>").appendTo("#sel")//添加下拉框的option
$("#sel").empty();//清空下拉框
獲取一組radio被選中項(xiàng)的值
var item = $('input[@name=items][@checked]').val();
獲取select被選中項(xiàng)的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二個(gè)元素為當(dāng)前選中值
$('#select_id')[0].selectedIndex = 1;
radio單選組的第二個(gè)元素為當(dāng)前選中值
$('input[@name=items]').get(1).checked = true;
獲取值:
文本框,文本區(qū)域:$("#txt").attr("value");
多選框checkbox:$("#checkbox_id").attr("value");
單選組radio: $("input[@type=radio][@checked]").val();
下拉框select: $('#sel').val();
控制表單元素:
文本框,文本區(qū)域:$("#txt").attr("value",'');//清空內(nèi)容
$("#txt").attr("value",'11');//填充內(nèi)容
多選框checkbox: $("#chk1").attr("checked",'');//不打勾
$("#chk2").attr("checked",true);//打勾
if($("#chk1").attr('checked')==undefined) //判斷是否已經(jīng)打勾
單選組radio: $("input[@type=radio]").attr("checked",'2');//設(shè)置value=2的項(xiàng)目為當(dāng)前選中項(xiàng)
下拉框select: $("#sel").attr("value",'-sel3');//設(shè)置value=-sel3的項(xiàng)目為當(dāng)前選中項(xiàng)
$("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//添加下拉框的option
$("#sel").empty();//清空下拉框



強(qiáng)強(qiáng) 2010-09-06 16:49 發(fā)表評(píng)論
]]>
判斷瀏覽器http://www.aygfsteel.com/lyjjq/articles/329503.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Fri, 20 Aug 2010 11:38:00 GMThttp://www.aygfsteel.com/lyjjq/articles/329503.htmlhttp://www.aygfsteel.com/lyjjq/comments/329503.htmlhttp://www.aygfsteel.com/lyjjq/articles/329503.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/329503.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/329503.html var browser = {
 'isIE' : (navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0),
 'isFirefox' : navigator.userAgent.indexOf('Firefox') >= 0,
 'isOpera' : navigator.userAgent.indexOf('Opera') >= 0
 };
 alert('ie:'+browser.isIE);
 alert('isfirefox:'+browser.isFirefox);
 

強(qiáng)強(qiáng) 2010-08-20 19:38 發(fā)表評(píng)論
]]>
urlencodehttp://www.aygfsteel.com/lyjjq/articles/328522.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Wed, 11 Aug 2010 04:32:00 GMThttp://www.aygfsteel.com/lyjjq/articles/328522.htmlhttp://www.aygfsteel.com/lyjjq/comments/328522.htmlhttp://www.aygfsteel.com/lyjjq/articles/328522.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/328522.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/328522.html實(shí)現(xiàn)一個(gè)功能需要把一個(gè)中文詞語(yǔ)編碼后拼到百度的URL中,在新窗口打開(kāi),實(shí)現(xiàn)搜索,需要一個(gè)類似與PHP中的URlencode的功能,找了好久都沒(méi)找到。escape、encodeURI、encodeURIComponent都不行。忙活了半天,終于讓我找到了,趕緊收藏下來(lái)。

<script language="vbscript">
Function str2asc(strstr)
str2asc = hex(asc(strstr))
End Function
Function asc2str(ascasc)
asc2str = chr(ascasc)
End Function
</script>
<script language="javascript" type="text/javascript">
function UrlEncode(str){
   var ret="";
   var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%";
   for(var i=0;i<str.length;i++){
   var chr = str.charAt(i);
     var c=str2asc(chr);
     if(parseInt("0x"+c) > 0x7f){
       ret+="%"+c.slice(0,2)+"%"+c.slice(-2);
     }else{
       if(chr==" ")
         ret+="+";
       else if(strSpecial.indexOf(chr)!=-1)
         ret+="%"+c.toString(16);
       else
         ret+=chr;
     }
   }
   return ret;
}
</script>

用這樣的辦法調(diào)用:

<script language="javascript" type="text/javascript">
alert(UrlEncode("孫毓波大好人"));
</script>



強(qiáng)強(qiáng) 2010-08-11 12:32 發(fā)表評(píng)論
]]>
最后一個(gè)奇數(shù)漢字出現(xiàn)亂碼解決方案http://www.aygfsteel.com/lyjjq/articles/328073.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Thu, 05 Aug 2010 13:57:00 GMThttp://www.aygfsteel.com/lyjjq/articles/328073.htmlhttp://www.aygfsteel.com/lyjjq/comments/328073.htmlhttp://www.aygfsteel.com/lyjjq/articles/328073.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/328073.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/328073.html1.統(tǒng)一用UTF-8編碼,即Tomcat的server.xml、頁(yè)面、過(guò)濾器都用UTF-8
2.
請(qǐng)求參數(shù),需要編碼

<a href="newsAction?name=<%=java.net.URLEncoder.encode("表數(shù)據(jù)管理","UTF-8")%>"
target="frameset">Xls表數(shù)據(jù)管理 </a>

假如是java代碼的話直接寫java.net.URLEncoder.encode("測(cè)試嗎","UTF-8");

下面引用Qieqie的一段代碼:

Java代碼 復(fù)制代碼
  1. public static void main(String[] args) throws UnsupportedEncodingException {   
  2.     //給定某3個(gè)漢字   
  3.     String src = "你好啊";   
  4.     //String src = "一二三";   
  5.        
  6.     //瀏覽器進(jìn)行utf-8編碼,并傳送到服務(wù)器   
  7.     byte[] bytes1 = src.getBytes("utf-8");   
  8.     System.out.println(bytes1.length);//9   
  9.        
  10.     //tomcat以gbk方式解碼(這個(gè)片段的說(shuō)明僅針對(duì)gbk處理漢字的情況)   
  11.     //如果一對(duì)漢字字節(jié)不符合gbk編碼規(guī)范,則每個(gè)字節(jié)使用'?'(ascii 63)代替   
  12.     //萬(wàn)幸的話,只是最后一個(gè)(第9個(gè))字節(jié)因不能成對(duì),變成問(wèn)號(hào)(比如當(dāng)src="你好啊"時(shí))   
  13.     //不幸的話,中間某些字節(jié)就通不過(guò)gbk編碼規(guī)范出現(xiàn)'?'了(比如當(dāng)src="一二三"時(shí))   
  14.     //總之temp的最后一位必定是問(wèn)號(hào)'?'   
  15.     String temp = new String(bytes1, "gbk");    
  16.        
  17.     //你的action中的代碼   
  18.     //由于以上的tomcat以gbk解釋utf-8不能成功   
  19.     //所以此時(shí)bytes2和bytes1不一樣   
  20.     byte[] bytes2 = temp.getBytes("gbk");   
  21.     System.out.println(bytes2.length);   
  22.     for (int i = 0; i < bytes1.length; i++) {   
  23.         System.out.print(bytes1[i] & 0xff);   
  24.         System.out.print("\t");   
  25.     }   
  26.     System.out.println();   
  27.     for (int i = 0; i < bytes2.length; i++) {   
  28.         System.out.print(bytes2[i] & 0xff);   
  29.         System.out.print("\t");   
  30.     }   
  31.     System.out.println();   
  32.   
  33.     //構(gòu)建出來(lái)的dest自然不是原先的src   
  34.     String dest = new String(bytes2, "utf-8");   
  35.     System.out.println(dest);   
  36.        
  37. }  


強(qiáng)強(qiáng) 2010-08-05 21:57 發(fā)表評(píng)論
]]>
jQuery 表單插件 jQuery.form http://www.aygfsteel.com/lyjjq/articles/327808.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Tue, 03 Aug 2010 04:10:00 GMThttp://www.aygfsteel.com/lyjjq/articles/327808.htmlhttp://www.aygfsteel.com/lyjjq/comments/327808.htmlhttp://www.aygfsteel.com/lyjjq/articles/327808.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/327808.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/327808.htmljQuery表單插件 jQuery.form
時(shí)間:2009-11-28 11:41    來(lái)源:未知    作者:雪山飛鵠
核心提示:jQuery 表單插件 jQuery.form 本文電子文檔下載 這是一個(gè)全面支持表單的 jQuery 插件,支持文件上傳,包含以下一些方法: -ajaxForm -ajaxSubmit - formToArray - formSerialize - fieldSerialize - fieldValue - clearForm - clearFields - resetForm 使用
  jQuery表單插件 jQuery.form                                           本文電子文檔下載

這是一個(gè)全面支持表單的jQuery插件,支持文件上傳,包含以下一些方法:

-ajaxForm
-ajaxSubmit
- formToArray
- formSerialize
- fieldSerialize
- fieldValue
- clearForm
- clearFields
- resetForm

使用時(shí)你必須依次引入jquery.jsjquery.form.js,并且順序不能顛倒

示例代碼:

// wait for the DOM to be loaded 
$(document).ready(function() {  
   // bind 'myForm' and provide a simple callback function   
   $('#myForm').ajaxForm(function() {   
       alert("Thank you for your comment!");  
    }); 
}); 


項(xiàng)目主頁(yè): http://malsup.com/jquery/form/
下載地址: http://malsup.com/jquery/form/jquery.form.js


表單插件API

英文原文:http://www.malsup.com/jquery/form/#api

表單插件API提供了幾個(gè)方法,讓你輕松管理表單數(shù)據(jù)和進(jìn)行表單提交。

ajaxForm()

增加所有需要的事件監(jiān)聽(tīng)器,為AJAX提交表單做好準(zhǔn)備。ajaxForm不能提交表單。在documentready函數(shù)中,使用ajaxForm來(lái)為AJAX提交表單進(jìn)行準(zhǔn)備。ajaxForm接受0個(gè)或1個(gè)參數(shù)。這個(gè)單個(gè)的參數(shù)既可以是一個(gè)回調(diào)函數(shù),也可以是一個(gè)Options對(duì)象。
可鏈接(Chainable):可以。

實(shí)例:

$('#myFormId').ajaxForm();

ajaxSubmit()

馬上由AJAX來(lái)提交表單。大多數(shù)情況下,都是調(diào)用ajaxSubmit來(lái)對(duì)用戶提交表單進(jìn)行響應(yīng)。ajaxSubmit接受0個(gè)或1個(gè)參數(shù)。這個(gè)單個(gè)的參數(shù)既可以是一個(gè)回調(diào)函數(shù),也可以是一個(gè)Options對(duì)象。
可鏈接(Chainable):可以。

實(shí)例:

// 綁定表單提交事件處理器
$('#myFormId').submit(function() {
    // 提交表單
    $(this).ajaxSubmit();
    // 為了防止普通瀏覽器進(jìn)行表單提交和產(chǎn)生頁(yè)面導(dǎo)航(防止頁(yè)面刷新?)返回false
    return false;
   });

formSerialize()

將表單串行化(或序列化)成一個(gè)查詢字符串。這個(gè)方法將返回以下格式的字符串:name1=value1&name2=value2
可鏈接(Chainable):不能, 這個(gè)方法返回一個(gè)字符串。

實(shí)例:

var queryString = $('#myFormId').formSerialize();

// 現(xiàn)在可以使用$.get$.post$.ajax等來(lái)提交數(shù)據(jù)
$.post('myscript.php', queryString);

fieldSerialize()

將表單的字段元素串行化(或序列化)成一個(gè)查詢字符串。當(dāng)只有部分表單字段需要進(jìn)行串行化(或序列化)時(shí),這個(gè)就方便了。這個(gè)方法將返回以下格式的字符串:name1=value1&name2=value2
可鏈接(Chainable):不能,這個(gè)方法返回一個(gè)字符串。

實(shí)例:

var queryString = $('#myFormId .specialFields').fieldSerialize();


fieldValue()

返回匹配插入數(shù)組中的表單元素值。從0.91版起,該方法將總是以數(shù)組的形式返回?cái)?shù)據(jù)。如果元素值被判定可能無(wú)效,則數(shù)組為空,否則它將包含一個(gè)或多于一個(gè)的元素值。
可鏈接(Chainable):不能,該方法返回?cái)?shù)組。

實(shí)例:

// 取得密碼輸入值
var value = $('#myFormId :password').fieldValue(); 
alert('The password is: ' + value[0]); 


resetForm()

通過(guò)調(diào)用表單元素原有的DOM方法,將表單恢復(fù)到初始狀態(tài)。
可鏈接(Chainable):可以。

實(shí)例:

$('#myFormId').resetForm();


clearForm()

清除表單元素。該方法將所有的文本(text)輸入字段、密碼(password)輸入字段和文本區(qū)域(textarea)字段置空,清除任何select元素中的選定,以及將所有的單選(radio)按鈕和多選(checkbox)按鈕重置為非選定狀態(tài)。
可鏈接(Chainable):可以。

$('#myFormId').clearForm();


clearFields()

清除字段元素。只有部分表單元素需要清除時(shí)才方便使用。
可鏈接(Chainable):可以。

$('#myFormId .specialFields').clearFields();

Options對(duì)象

ajaxFormajaxSubmit都支持眾多的選項(xiàng)參數(shù),這些選項(xiàng)參數(shù)可以使用一個(gè)Options對(duì)象來(lái)提供。Options只是一個(gè)JavaScript對(duì)象,它包含了如下一些屬性與值的集合:

target

指明頁(yè)面中由服務(wù)器響應(yīng)進(jìn)行更新的元素。元素的值可能被指定為一個(gè)jQuery選擇器字符串,一個(gè)jQuery對(duì)象,或者一個(gè)DOM元素。
默認(rèn)值:null

url

指定提交表單數(shù)據(jù)的URL
默認(rèn)值:表單的action屬性值

type

指定提交表單數(shù)據(jù)的方法(method):“GET”“POST”
默認(rèn)值:表單的method屬性值(如果沒(méi)有找到默認(rèn)為“GET”)。

beforeSubmit

表單提交前被調(diào)用的回調(diào)函數(shù)。“beforeSubmit”回調(diào)函數(shù)作為一個(gè)鉤子(hook),被提供來(lái)運(yùn)行預(yù)提交邏輯或者校驗(yàn)表單數(shù)據(jù)。如果“beforeSubmit”回調(diào)函數(shù)返回false,那么表單將不被提交。“beforeSubmit”回調(diào)函數(shù)帶三個(gè)調(diào)用參數(shù):數(shù)組形式的表單數(shù)據(jù),jQuery表單對(duì)象,以及傳入ajaxForm/ajaxSubmit中的Options對(duì)象。表單數(shù)組接受以下方式的數(shù)據(jù):

[ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]

默認(rèn)值:null

success

表單成功提交后調(diào)用的回調(diào)函數(shù)。如果提供“success”回調(diào)函數(shù),當(dāng)從服務(wù)器返回響應(yīng)后它被調(diào)用。然后由dataType選項(xiàng)值決定傳回responseText還是responseXML的值。
默認(rèn)值:null

dataType

期望返回的數(shù)據(jù)類型。null“xml”“script”或者“json”其中之一。dataType提供一種方法,它規(guī)定了怎樣處理服務(wù)器的響應(yīng)。這個(gè)被直接地反映到jQuery.httpData方法中去。下面的值被支持:

'xml':如果dataType == 'xml',將把服務(wù)器響應(yīng)作為XML來(lái)對(duì)待。同時(shí),如果“success”回調(diào)方法被指定, 將傳回responseXML值。

'json':如果dataType == 'json' 服務(wù)器響應(yīng)將被求值,并傳遞到“success”回調(diào)方法,如果它被指定的話。

'script':如果dataType == 'script' 服務(wù)器響應(yīng)將求值成純文本。

默認(rèn)值:null(服務(wù)器返回responseText值)

semantic

Boolean flag indicating whether data must be submitted in strict semantic order (slower). Note that the normal form serialization is done in semantic order with the exception of input elements of type="image". You should only set the semantic option to true if your server has strict semantic requirements and your form contains an input element of type="image".
布爾標(biāo)志,表示數(shù)據(jù)是否必須嚴(yán)格按照語(yǔ)義順序(slower?)來(lái)進(jìn)行提交。注意:一般來(lái)說(shuō),表單已經(jīng)按照語(yǔ)義順序來(lái)進(jìn)行了串行化(或序列化),除了type="image"input元素。如果你的服務(wù)器有嚴(yán)格的語(yǔ)義要求,以及表單中包含有一個(gè)type="image"input元素,就應(yīng)該將semantic設(shè)置為true。(譯注:這一段由于無(wú)法理解,翻譯出來(lái)可能語(yǔ)不達(dá)意,但請(qǐng)達(dá)人指正。)
默認(rèn)值:false

resetForm

布爾標(biāo)志,表示如果表單提交成功是否進(jìn)行重置。
Default value: null

clearForm

布爾標(biāo)志,表示如果表單提交成功是否清除表單數(shù)據(jù)。
默認(rèn)值:null

實(shí)例:

// 準(zhǔn)備好Options對(duì)象
var options = {
    target:     '#divToUpdate',
    url:        'comment.php',
    success: function() {
      alert('Thanks for your comment!');
    } };

   // options傳給ajaxForm
$('#myForm').ajaxForm(options);


注意:Options對(duì)象還可以用來(lái)將值傳遞給jQuery$.ajax方法。如果你熟悉$.ajax所支持的options,你可以利用它們來(lái)將Options對(duì)象傳遞給ajaxFormajaxSubmit

ajaxForm()適用于以表單提交方式處理ajax技術(shù)(需要提供表單的actionidmethod,最好在表單中提供submit按鈕)它大大簡(jiǎn)化了使用ajax技術(shù)提交表單時(shí)的數(shù)據(jù)傳遞問(wèn)題,使用ajaxForm()你不需要逐個(gè)的以JavaScript的方式獲取每個(gè)表單屬性的值,并且也不需要在請(qǐng)求路徑后面通過(guò)url重寫的方式傳遞數(shù)據(jù)。ajaxForm()會(huì)自動(dòng)收集當(dāng)前表單中每個(gè)屬性的值,然后將其以表單提交的方式提交到目標(biāo)url。這種方式提交數(shù)據(jù)較安全,并且使用起來(lái)更簡(jiǎn)單,不必寫過(guò)多冗余的JavaScript代碼

$(document).ready(function(){

         registerForm'表單id

data回調(diào)數(shù)據(jù)

        $('#registerForm').ajaxForm(function(data){

            alert(data);//彈出ajax請(qǐng)求后的回調(diào)結(jié)果

        });

});

ajaxSubmit()適用于以事件的機(jī)制以ajax提交form表單(超鏈接、圖片的click事件),該方法作用與ajaxForm()類似,但它更為靈活,因?yàn)樗蕾囉谑录C(jī)制,只要有事件存在就能使用該方法。你只需指定該formaction屬性即可,不需要提供submit按鈕。

$(document).ready(function(){

    $('#btn').click(function(){

            $('#registerForm').ajaxSubmit(function(data){

                alert(data);

            });

            return false;

    });

    });

該段代碼作用是在表單中idbtn的按鈕click事件觸發(fā)時(shí)通過(guò)ajaxSubmit()方法以ajax技術(shù)提交表單到表單的action所指路徑

formSerialize()是將一個(gè)form所有的表單元素name作為keyvalue作為值進(jìn)行序列化操作,這就需要你必須為每一個(gè)表單元素設(shè)置表單元素name屬性及填充表單元素value的值,最好也設(shè)置id方便jquery定位表單元素。若要使用此方法你必須設(shè)置表單元素name屬性及填充表單元素value的值,我在初次使用時(shí)就忘了設(shè)置name屬性,最后在同事的幫助下找了好久才發(fā)現(xiàn)此錯(cuò)誤。

var str=$('#registerForm').formSerialize(); // registerFormform id

alert(str);

fieldSerialize()是將form表單元素進(jìn)行序列化以name作為keyvalue作為值進(jìn)行序列化操作,這就需要你必須為每一個(gè)表單元素設(shè)置表單元素name屬性及填充表單元素value的值。

var str=$('#username). fieldSerialize();

alert(str);

其他方法不做總結(jié)了,用的話大家在googlebaidu一下相信會(huì)有很多令你滿意的答案的。
   本文電子文檔下載

來(lái)源:http://www.aygfsteel.com/sxyx2008/archive/2009/11/27/303877.html



強(qiáng)強(qiáng) 2010-08-03 12:10 發(fā)表評(píng)論
]]>
JS-如何讓兩個(gè)DIV的高度隱式同步-用了JQuery http://www.aygfsteel.com/lyjjq/articles/327508.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Thu, 29 Jul 2010 15:08:00 GMThttp://www.aygfsteel.com/lyjjq/articles/327508.htmlhttp://www.aygfsteel.com/lyjjq/comments/327508.htmlhttp://www.aygfsteel.com/lyjjq/articles/327508.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/327508.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/327508.html"rightbar").style.height得到的是auto.



首發(fā)于:http://www.xfuse.cn



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>無(wú)標(biāo)題文檔 </title>


  <SCRIPT LANGUAGE="JavaScript" src="http://code.jquery.com/jquery-latest.js"> </SCRIPT>


  <Script>


  </script>
</head>

<body>
<div>


  <div id=main style="float:left;width:600px; background:#ccc;">
  動(dòng)態(tài)生成的內(nèi)容,高度不定 <br>
  動(dòng)態(tài)生成的內(nèi)容,高度不定 <br>
  動(dòng)態(tài)生成的內(nèi)容,高度不定 <br>
  動(dòng)態(tài)生成的內(nèi)容,高度不定 <br>
  動(dòng)態(tài)生成的內(nèi)容,高度不定 <br>
  動(dòng)態(tài)生成的內(nèi)容,高度不定 <br>

  </div>
  <div id=rightbar style="float:right;width:300px; background:red; display:block">
  右邊欄,內(nèi)容比main少
  </div>
</div>
<script language="javascript">
window.onload=function(){

var he= $('#main').height();

$('#rightbar').height(he);

};
</script>
</html>
JS-如何讓兩個(gè)DIV的高度隱式同步-用了JQuery

強(qiáng)強(qiáng) 2010-07-29 23:08 發(fā)表評(píng)論
]]>
使用prototype.js 中 Ajax.Updater 類引發(fā)的問(wèn)題http://www.aygfsteel.com/lyjjq/articles/327421.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Thu, 29 Jul 2010 05:55:00 GMThttp://www.aygfsteel.com/lyjjq/articles/327421.htmlhttp://www.aygfsteel.com/lyjjq/comments/327421.htmlhttp://www.aygfsteel.com/lyjjq/articles/327421.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/327421.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/327421.html

 

(2006-11-24 18:10:00)
  分類:AJAX
prototype.js是由Sam Stephenson寫的一個(gè)javascript類庫(kù)。在使用prototype.js的過(guò)程中,覺(jué)得挺好用的,它提供了一些常用函數(shù)的簡(jiǎn)寫方式,對(duì)JavaScript類做了適當(dāng)?shù)臄U(kuò)展,最感興趣的地方也是它的AJAX能力。
下面是我仿照 prototype.js開(kāi)發(fā)者手冊(cè) 用 prototype.js中的Ajax.Updater類做的一個(gè)簡(jiǎn)單的例子,當(dāng)中遇到的一些問(wèn)題及解決方法:
Index.jsp:
Contents.jsp:

注意到了 /* ...  */中的內(nèi)容了嗎? 在Index.jsp頁(yè)面,在使用 new Ajax.Updater 函數(shù)時(shí),加上了 evalScripts:true 屬性,這樣才會(huì)執(zhí)行Content.jsp頁(yè)面中的JavaScript代碼。"但是值得提醒的是,像這個(gè)選項(xiàng)名 evalScripts 暗示的,這些腳本會(huì)被執(zhí)行,但是它們不會(huì)加入到 page 腳本中",所以Content.jsp 中的函數(shù)寫成了 sayHi = function(){...}這種形式(創(chuàng)建一個(gè)函數(shù)),而不是 function sayHi(){...} (聲明一個(gè)函數(shù)) 也不能加上var 關(guān)鍵字 var sayHi = function(){...}(當(dāng)前腳本的一個(gè)局部變量),具體的解釋可參考 prototype.js開(kāi)發(fā)者手冊(cè)。 我最想說(shuō)的是下面這個(gè)問(wèn)題,在Contents.jsp 頁(yè)面中我們是導(dǎo)入了另外一個(gè)js(import.js),并在sayHi函數(shù)中調(diào)用了import.js里的方法importFun(),運(yùn)行過(guò)程中會(huì)發(fā)現(xiàn)被導(dǎo)入的import.js里的函數(shù)不能被執(zhí)行,可是應(yīng)該怎么辦呢?? 呵呵,還好已經(jīng)有人(我們公司以前的技術(shù)支持-foxty,現(xiàn)在在北京,我一直向他學(xué)習(xí)的)解決了,解決辦法是在prototype.js的 evalScripts: function()加了一些內(nèi)容,原來(lái)屬性是這樣的:evalScripts: function() {return this.extractScripts().map(eval);},增加內(nèi)容后的代碼片斷如下所示:

中 Ajax.Updater 類引發(fā)的問(wèn)題" alt="使用prototype.js 中 Ajax.Updater 類引發(fā)的問(wèn)題" src="http://static12.photo.sina.com.cn/orignal/4b62e4a9bb5e011adcfcb" border=0 real_src="http://static12.photo.sina.com.cn/orignal/4b62e4a9bb5e011adcfcb">

相關(guān)內(nèi)容可以訪問(wèn) http://foxty.javaeye.com/blog/24497 這個(gè)網(wǎng)頁(yè)查看。



強(qiáng)強(qiáng) 2010-07-29 13:55 發(fā)表評(píng)論
]]>
prototype.js開(kāi)發(fā)手冊(cè)http://www.aygfsteel.com/lyjjq/articles/327420.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Thu, 29 Jul 2010 05:53:00 GMThttp://www.aygfsteel.com/lyjjq/articles/327420.htmlhttp://www.aygfsteel.com/lyjjq/comments/327420.htmlhttp://www.aygfsteel.com/lyjjq/articles/327420.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/327420.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/327420.html閱讀全文

強(qiáng)強(qiáng) 2010-07-29 13:53 發(fā)表評(píng)論
]]>
[總結(jié)]細(xì)線表格制作技巧-表格邊框樣式設(shè)置集錦 http://www.aygfsteel.com/lyjjq/articles/314722.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Sat, 06 Mar 2010 14:49:00 GMThttp://www.aygfsteel.com/lyjjq/articles/314722.htmlhttp://www.aygfsteel.com/lyjjq/comments/314722.htmlhttp://www.aygfsteel.com/lyjjq/articles/314722.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/314722.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/314722.html
關(guān)鍵字:細(xì)線表格 表格技巧 細(xì)線表格代碼 CSS細(xì)線表格
摘要:看到不少朋友在問(wèn)
細(xì)線表格如何設(shè)置,雖然簡(jiǎn)單,偶還是總結(jié)一下拿出來(lái),也方便新手學(xué)習(xí)。缺陷失誤之處請(qǐng)大家指點(diǎn).看的朋友如果有其他的實(shí)現(xiàn)方法,也希望能發(fā)布到這里,謝謝!

不知道怎么發(fā)布html執(zhí)行后的樣子,全是代碼,真不直觀,會(huì)的朋友指點(diǎn)下,謝謝!
暫時(shí),可以先把下面的代碼拷貝到記事本,保存,然后再修改擴(kuò)展名為html,打開(kāi),這樣看比較直觀。

<
style>
{ font-size:90%;}
font 
{ color:#0000CC;}
</style>
<font>下面的細(xì)線表格是用cellspacing來(lái)實(shí)現(xiàn)的,用表格的背景色做為邊框的顏色。</font>不方便的是每一行都要再設(shè)置一個(gè)背景色。
<table width="400" border="0" cellspacing="1" cellpadding="0"
 bgcolor="#000000">
  
<tr bgcolor="#006600">
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
  
<tr bgcolor="#FFFFFF">
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
</table>
<br />
< font>下面的細(xì)線表格是設(shè)置bordercolordark來(lái)實(shí)現(xiàn)的</font>,因?yàn)槟J(rèn)的border其實(shí)寬度是2,即使設(shè)置為1也沒(méi)用,bordercolorlight和bordercolordark一起作為表格的邊框。所以設(shè)置其中一個(gè)為背景色,表格邊框看起來(lái)就會(huì)細(xì)一些。
<table width="400" border="1" cellspacing="0" cellpadding="0"
bordercolor
="#000000" bordercolordark="#FFFFFF">
  
<tr bgcolor="#006600">
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
  
<tr>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
</table>
<br />
<font>下面的表格是用css來(lái)實(shí)現(xiàn)的。</font><br />
css技巧比較多,列舉幾種:
A:設(shè)置border="1"、bordercolor,再加上style="border-collapse:collapse;"。style里面的內(nèi)容就是css。
<table width="400" border="1" bordercolor="#000000" cellspacing="0"
 cellpadding
="0" style="border-collapse:collapse;">
  
<tr>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
  
<tr>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
</table>
<br />
B:這個(gè)用css來(lái)設(shè)置邊框,結(jié)果只顯示表格的最外層邊線。里面的線不顯示。
<table width="400" cellspacing="0" cellpadding="0"
style
="border:#000000 1px solid;">
  
<tr>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
  
<tr>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
</table>
<br />
C: 如果你想要頁(yè)面的所有表格都是細(xì)線表格,也不用一個(gè)一個(gè)去設(shè)置。因?yàn)檫@里是演示用,所以加上了id,你用的時(shí)候直接
 在head里面加上style標(biāo)簽,里面寫 table {border-collapse:collapse;} td {border:#000000 1px solid;},所有該頁(yè)的table就都是細(xì)線了。
<style>
#tab1 
{border-collapse:collapse;}
#tab1 td 
{border:#000000 1px solid;}
</style>
<table id="tab1" width="400">
  
<tr>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
  
<tr>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
</table>
<br />
<br />

<font>表格邊框控制的其他方法(rules和frame):</font><br />說(shuō)明:<br />
1、這兩個(gè)屬性有時(shí)候設(shè)置會(huì)看不到作用,這是因?yàn)榕c表格邊框的css設(shè)置沖突。所以說(shuō)如果需要這些效果,并且還需要細(xì)線,那就用下面的方式來(lái)實(shí)現(xiàn)即設(shè)置這三個(gè)屬性,border="1" bordercolor="#000000" style="border-collapse:collapse;",然后再設(shè)置rules和frame,如果你測(cè)試到有其他的方法,希望能發(fā)布出來(lái)和大家共享。
<br />
2、下面的效果只是我列舉出來(lái)做演示用的,靈活設(shè)置這些屬性可以做出更多效果。
<br />
 rules="cols"的效果(中間的橫線沒(méi)有了)
<table width="400" border="1" bordercolor="#000000"
style
="border-collapse:collapse;" rules="cols">
  
<tr>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
  
<tr>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
</table>
<br />
frame="void"的效果(外邊線沒(méi)有了)
<table width="400" border="1" bordercolor="#000000"
style
="border-collapse:collapse;" frame="void">
  
<tr>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
  
<tr>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
</table>
<br />
rules和frame結(jié)合的效果(frame="hsides" rules="rows",只留下橫線)
<table width="400" border="1" bordercolor="#000000"
style
="border-collapse:collapse;" frame="hsides" rules="rows">
  
<tr>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
  
<tr>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
  
<tr>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
  
<tr>
    
<td>&nbsp;</td>
    
<td>&nbsp;</td>
  
</tr>
</table>


強(qiáng)強(qiáng) 2010-03-06 22:49 發(fā)表評(píng)論
]]>
js控制圖片的顯示最寬和最高值,取js對(duì)象的全部屬性http://www.aygfsteel.com/lyjjq/articles/312408.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Tue, 09 Feb 2010 05:24:00 GMThttp://www.aygfsteel.com/lyjjq/articles/312408.htmlhttp://www.aygfsteel.com/lyjjq/comments/312408.htmlhttp://www.aygfsteel.com/lyjjq/articles/312408.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/312408.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/312408.html<html>
<head>
<script>


 

function allProps(obj){
    // 用來(lái)保存所有的屬性名稱和值
   var props = "";
 
    // 開(kāi)始遍歷
   if(typeof obj== "string"){
    props =obj;
   }else{
    if(obj!=null&& (typeof obj =="object")){
      for(var p in obj){
          // 方法
          if(typeof(obj[p])=="function"){ 
            
          }else{ 
              // p 為屬性名稱,obj[p]為對(duì)應(yīng)屬性的值
              props+= p + "=" + obj[p] + "\r\n";
          }
      }
    }
   }


    // 最后顯示所有的屬性
    alert(props);
}

//js控制圖片的顯示最寬和最高值
function drawImage(ImgId,maxwidth,maxheight){
 //本程序?qū)D像控制在寬為maxwidth且高為maxheight的框內(nèi)
 //ImgD是圖像ID,maxwidth、maxheight是圖像最大顯示寬度和高度
 var ImgD=document.getElementById(ImgId);
 allProps(ImgD);
 var image=new Image();
 image.src=ImgD.src;
 var imgwidth=image.width;
 var imgheight=image.height;
 if(imgwidth>0 && imgheight>0 && maxwidth>0 && maxheight>0){
  if(imgwidth>maxwidth || imgheight>maxheight){
     if(imgwidth/imgheight>= maxwidth/maxheight){
       ImgD.width=maxwidth;
       ImgD.height=(imgheight*maxwidth)/imgwidth;
     }
     else{
      ImgD.height=maxheight;
      ImgD.width=(imgwidth*maxheight)/imgheight;
     }
  }else{
     ImgD.width=imgwidth;
     ImgD.height=imgheight;
  }
 }
}
</script>
</head>
<body>
 <img id="thisimage" src="http://d5.sina.com.cn/201101/31/283911_750-450.jpg">
 <script>
  drawImage('thisimage',80,80);
 </script>
</body>
</html>



強(qiáng)強(qiáng) 2010-02-09 13:24 發(fā)表評(píng)論
]]>
js Mathhttp://www.aygfsteel.com/lyjjq/articles/309675.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Fri, 15 Jan 2010 05:02:00 GMThttp://www.aygfsteel.com/lyjjq/articles/309675.htmlhttp://www.aygfsteel.com/lyjjq/comments/309675.htmlhttp://www.aygfsteel.com/lyjjq/articles/309675.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/309675.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/309675.html   Math.round(x):四舍五入。  
  Math.floor(x):比x小的最大值。  
  Math.round(x)返回long型,其余的返回double   型。

強(qiáng)強(qiáng) 2010-01-15 13:02 發(fā)表評(píng)論
]]>
jquery選擇器 http://www.aygfsteel.com/lyjjq/articles/309021.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Mon, 11 Jan 2010 06:41:00 GMThttp://www.aygfsteel.com/lyjjq/articles/309021.htmlhttp://www.aygfsteel.com/lyjjq/comments/309021.htmlhttp://www.aygfsteel.com/lyjjq/articles/309021.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/309021.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/309021.html

— 基本選擇器

— $("#txt").css("background-color","red");

— 設(shè)置idtxt的元素

— $("p").css("background-color","blue");

— 設(shè)置p元素

— $(".myclass").css("background-color","yellow");

— 設(shè)置classmyclass的元素

— $(".myclass,#txt").css("background-color","gray");

— 設(shè)置classmyclass以及idtxt的元素

 

— 層次選擇器

— $("#mydiv span").css("background-color","green");

— 設(shè)置mydiv所有span子孫元素

— $("#mydiv>span").css("background-color","pink");

— 設(shè)置mydiv所有span兒子元素

— $("#mydiv+span").css("background-color","pink");

— 設(shè)置mydiv后所有span兄弟元素

 

— 表單選擇器

— $(":input").css("background-color","green");

— 設(shè)置所有表單元素

— $(":text").css("background-color","pink");

— 設(shè)置所有文本框

— $(":button").css("background-color","pink");

— 設(shè)置所有按鈕

 

— 基本過(guò)濾器

— $(".class1:first").css("background-color","green");

— 設(shè)置所有classclass1的元素的第一項(xiàng)

— $(".class1:last").css("background-color","green");

— 設(shè)置所有classclass1的元素的最后一項(xiàng)

— $(".class1:even").css("background-color","green");

— 設(shè)置所有classclass1的元素的偶數(shù)項(xiàng)

— $(".class1:odd").css("background-color","green");

— 設(shè)置所有classclass1的元素的奇數(shù)項(xiàng)

— $(".class1:eq(3)").css("background-color","green");

— 設(shè)置所有classclass1的元素中下標(biāo)為3的項(xiàng)

— $(".class1:gt(3)").css("background-color","green");

— 設(shè)置所有classclass1的元素中下標(biāo)大于3的項(xiàng)

— $(".class1:lt(3)").css("background-color","green");

— 設(shè)置所有classclass1的元素中下標(biāo)小于3的項(xiàng)

— $(".class1:not(p)").css("background-color","green");

— 設(shè)置所有classclass1的元素中不為p的項(xiàng)

 

— 屬性過(guò)濾器

— $(".class1[id]").css("background-color","green");

— 設(shè)置所有classclass1的元素中具有id屬性的項(xiàng)

— $(".class1[name='txt']").css("background-color","green");

— 設(shè)置所有classclass1的元素中name屬性值為txt的項(xiàng)

— $(".class1[name!='txt']").css("background-color","green");

— 設(shè)置所有classclass1的元素中name屬性值為txt的項(xiàng)

— $(".class1[name^='txt']").css("background-color","green");

— 設(shè)置所有classclass1的元素中name屬性值以txt開(kāi)頭的項(xiàng)

— $(".class1[name$='txt']").css("background-color","green");

— 設(shè)置所有classclass1的元素中name屬性值以txt結(jié)尾的項(xiàng)

— $(".class1[name*='txt']").css("background-color","green");

— 設(shè)置所有classclass1的元素中name屬性值包含txt的項(xiàng)

— $(".class1[id][name='txt']").css("background-color","green");

— 設(shè)置所有classclass1的元素中有id屬性并且name屬性值為txt的項(xiàng)

 

— 表單過(guò)濾器

— $(":text:disabled").css("background-color","green");

— 設(shè)置所有禁用的文本框

— $(":button:enabled").css("background-color","green");

— 設(shè)置所有啟用的按鈕

— $(":checkbox:checked").css("background-color","green");

— 設(shè)置所有選中的復(fù)選框

 

— 內(nèi)容過(guò)濾器

— $("div:contains('gcd') ").css("background-color","green");

— 設(shè)置所有包含gcd字符串的div

— $("div:has(p)").css("background-color","green");

— 設(shè)置所有包含段落的div

— $("td:empty").css("background-color","green");

— 設(shè)置所沒(méi)有內(nèi)容的單元格



強(qiáng)強(qiáng) 2010-01-11 14:41 發(fā)表評(píng)論
]]>
javascript 取頁(yè)面的各種寬度http://www.aygfsteel.com/lyjjq/articles/307126.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Thu, 24 Dec 2009 04:15:00 GMThttp://www.aygfsteel.com/lyjjq/articles/307126.htmlhttp://www.aygfsteel.com/lyjjq/comments/307126.htmlhttp://www.aygfsteel.com/lyjjq/articles/307126.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/307126.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/307126.html   {
      var s = "";
      s += " 網(wǎng)頁(yè)可見(jiàn)區(qū)域?qū)挘?+ document.body.clientWidth;
      s += " 網(wǎng)頁(yè)可見(jiàn)區(qū)域高:"+ document.body.clientHeight;
      s += " 網(wǎng)頁(yè)可見(jiàn)區(qū)域?qū)挘?+ document.body.offsetWidth + " (包括邊線和滾動(dòng)條得寬)";
      s += " 網(wǎng)頁(yè)可見(jiàn)區(qū)域高:"+ document.body.offsetHeight + " (包括邊線得寬)";
      s += " 網(wǎng)頁(yè)正文全文寬:"+ document.body.scrollWidth;
      s += " 網(wǎng)頁(yè)正文全文高:"+ document.body.scrollHeight;
      s += " 網(wǎng)頁(yè)被卷去得高(ff):"+ document.body.scrollTop;
      s += " 網(wǎng)頁(yè)被卷去得高(ie):"+ document.documentElement.scrollTop;
      s += " 網(wǎng)頁(yè)被卷去得左:"+ document.body.scrollLeft;
      s += " 網(wǎng)頁(yè)正文部分上:"+ window.screenTop;
      s += " 網(wǎng)頁(yè)正文部分左:"+ window.screenLeft;
      s += " 屏幕分辨率得高:"+ window.screen.height;
      s += " 屏幕分辨率得寬:"+ window.screen.width;
      s += " 屏幕可用工做區(qū)高度:"+ window.screen.availHeight;
      s += " 屏幕可用工做區(qū)寬度:"+ window.screen.availWidth;
      s += " 你得屏幕設(shè)置是 "+ window.screen.colorDepth +" 位彩色";
      s += " 你得屏幕設(shè)置 "+ window.screen.deviceXDPI +" 像素/英寸";
      alert (s);
  }
  function myunload(){   
   if((event.clientX>(window.screen.width-30)) && (event.clientY<0) ||event.altKey){
       DataLoad.src = 'http://"
   event.returnValue='感謝您的積極參與。';       
      }
  }
  

強(qiáng)強(qiáng) 2009-12-24 12:15 發(fā)表評(píng)論
]]>
將收集的正則表達(dá)式歸納。以后持續(xù)跟進(jìn)。http://www.aygfsteel.com/lyjjq/articles/304069.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Sat, 28 Nov 2009 17:32:00 GMThttp://www.aygfsteel.com/lyjjq/articles/304069.htmlhttp://www.aygfsteel.com/lyjjq/comments/304069.htmlhttp://www.aygfsteel.com/lyjjq/articles/304069.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/304069.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/304069.html匹配中文字符的正則表達(dá)式: [\u4e00-\u9fa5]
評(píng)注:匹配中文還真是個(gè)頭疼的事,有了這個(gè)表達(dá)式就好辦了

匹配雙字節(jié)字符(包括漢字在內(nèi)):[^\x00-\xff]
評(píng)注:可以用來(lái)計(jì)算字符串的長(zhǎng)度(一個(gè)雙字節(jié)字符長(zhǎng)度計(jì)2,ASCII字符計(jì)1)

字符串中只能輸入漢字:"^[\u4e00-\u9fa5]{0,}$"

評(píng)注:可以對(duì)漢字串進(jìn)行驗(yàn)證

匹配空白行的正則表達(dá)式:\n\s*\r
評(píng)注:可以用來(lái)刪除空白行

匹配HTML標(biāo)記的正則表達(dá)式:< (\S*?)[^>]*>.*?|< .*? />
評(píng)注:網(wǎng)上流傳的版本太糟糕,上面這個(gè)也僅僅能匹配部分,對(duì)于復(fù)雜的嵌套標(biāo)記依舊無(wú)能為力

匹配首尾空白字符的正則表達(dá)式:^\s*|\s*$
評(píng)注:可以用來(lái)刪除行首行尾的空白字符(包括空格、制表符、換頁(yè)符等等),非常有用的表達(dá)式

匹配Email地址的正則表達(dá)式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
評(píng)注:表單驗(yàn)證時(shí)很實(shí)用

匹配網(wǎng)址URL的正則表達(dá)式:[a-zA-z]+://[^\s]*
評(píng)注:網(wǎng)上流傳的版本功能很有限,上面這個(gè)基本可以滿足需求

匹配帳號(hào)是否合法(字母開(kāi)頭,允許5-16字節(jié),允許字母數(shù)字下劃線):^[a-zA-Z][a-zA-Z0-9_]{4,15}$
評(píng)注:表單驗(yàn)證時(shí)很實(shí)用

匹配國(guó)內(nèi)電話號(hào)碼:\d{3}-\d{8}|\d{4}-\d{7}
評(píng)注:匹配形式如 0511-4405222 或 021-87888822

匹配騰訊QQ號(hào):[1-9][0-9]{4,}
評(píng)注:騰訊QQ號(hào)從10000開(kāi)始

匹配中國(guó)郵政編碼:[1-9]\d{5}(?!\d)
評(píng)注:中國(guó)郵政編碼為6位數(shù)字

匹配身份證:\d{15}|\d{18}
評(píng)注:中國(guó)的身份證為15位或18位

匹配ip地址:\d+\.\d+\.\d+\.\d+
評(píng)注:提取ip地址時(shí)有用

匹配特定數(shù)字:
整數(shù)或者小數(shù):^[0-9]+\.{0,1}[0-9]{0,2}$
只能輸入數(shù)字:"^[0-9]*$"。
只能輸入n位的數(shù)字:"^\d{n}$"。
只能輸入至少n位的數(shù)字:"^\d{n,}$"。
只能輸入m~n位的數(shù)字:。"^\d{m,n}$"
只能輸入零和非零開(kāi)頭的數(shù)字:"^(0|[1-9][0-9]*)$"。
只能輸入有兩位小數(shù)的正實(shí)數(shù):"^[0-9]+(.[0-9]{2})?$"。
只能輸入有1~3位小數(shù)的正實(shí)數(shù):"^[0-9]+(.[0-9]{1,3})?$"。
只能輸入非零的正整數(shù):"^\+?[1-9][0-9]*$"。
只能輸入非零的負(fù)整數(shù):"^\-[1-9][]0-9"*$。

只能輸入非負(fù)整數(shù)(正整數(shù)+0):"^\d+$"      或者  ^[1-9]\d*|0$
只能輸入正整數(shù):"^[0-9]*[1-9][0-9]*$"  或者  ^[1-9]\d*$
只能輸入非正整數(shù)(負(fù)整數(shù)+0):"^((-\d+)|(0+))$"  或者  ^-[1-9]\d*|0$
只能輸入負(fù)整數(shù):"^-[0-9]*[1-9][0-9]*$"  或者 ^-[1-9]\d*$
只能輸入整數(shù):"^-?\d+$"    或者 ^-?[1-9]\d*$

只能輸入非負(fù)浮點(diǎn)數(shù)(正浮點(diǎn)數(shù)+0):"^\d+(\.\d+)?$"   或者  ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$
只能輸入正浮點(diǎn)數(shù):"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$"   或者  ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$

只能輸入非正浮點(diǎn)數(shù)(負(fù)浮點(diǎn)數(shù)+0):"^((-\d+(\.\d+)?)|(0+(\.0+)?))$"   或者  ^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$

只能輸入負(fù)浮點(diǎn)數(shù):"^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$"

或者 ^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$
只能輸入浮點(diǎn)數(shù):"^(-?\d+)(\.\d+)?$"  或者  ^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$

匹配特定字符串:
只能輸入長(zhǎng)度為3的字符:"^.{3}$"。
只能輸入由26個(gè)英文字母組成的字符串:"^[A-Za-z]+$"。
只能輸入由26個(gè)大寫英文字母組成的字符串:"^[A-Z]+$"。
只能輸入由26個(gè)小寫英文字母組成的字符串:"^[a-z]+$"。
只能輸入由數(shù)字和26個(gè)英文字母組成的字符串:"^[A-Za-z0-9]+$"。

只能輸入由數(shù)字、26個(gè)英文字母或者下劃線組成的字符串:"^\w+$"。


驗(yàn)證用戶密碼:"^[a-zA-Z]\w{5,17}$"正確格式為:以字母開(kāi)頭,長(zhǎng)度在6~18之間,只能包含字符、數(shù)字和下劃線。
驗(yàn)證是否含有^%&',;=?$"等字符:"[^%&',;=?$\x22]+"。
驗(yàn)證Email地址:"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"。
驗(yàn)證InternetURL:"^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$"。
驗(yàn)證電話號(hào)碼:"^(\(\d{3,4}-)|\d{3.4}-)?\d{7,8}$"正確格式為:"XXX-XXXXXXX"、"XXXX-XXXXXXXX"、"XXX-XXXXXXX"、"XXX-XXXXXXXX"、"XXXXXXX"和"XXXXXXXX"。
驗(yàn)證身份證號(hào)(15位或18位數(shù)字):"^\d{15}|\d{18}$"。
驗(yàn)證一年的12個(gè)月:"^(0?[1-9]|1[0-2])$"正確格式為:"01"~"09"和"1"~"12"。
驗(yàn)證一個(gè)月的31天:"^((0?[1-9])|((1|2)[0-9])|30|31)$"正確格式為;"01"~"09"和"1"~"31"。


在asp.net中使用RegularExpressionValidator控件,可以將正則表達(dá)式和asp.net控件結(jié)合起來(lái)。

例子:如何檢查當(dāng)TextBox設(shè)置為多行時(shí)是不是超長(zhǎng)了?
<asp:RegularExpressionValidator id="revTextBox1" runat="server" ForeColor="Red" Display="Dynamic" ControlToValidate="textBox1" ValidationExpression="(\w|\W){1,100}">格式錯(cuò)誤-只能輸入不超過(guò)100個(gè)字符< /asp:RegularExpressionValidator>



強(qiáng)強(qiáng) 2009-11-29 01:32 發(fā)表評(píng)論
]]>
幾個(gè)button的css效果,看上去還不錯(cuò)http://www.aygfsteel.com/lyjjq/articles/302290.html強(qiáng)強(qiáng)強(qiáng)強(qiáng)Fri, 13 Nov 2009 15:37:00 GMThttp://www.aygfsteel.com/lyjjq/articles/302290.htmlhttp://www.aygfsteel.com/lyjjq/comments/302290.htmlhttp://www.aygfsteel.com/lyjjq/articles/302290.html#Feedback0http://www.aygfsteel.com/lyjjq/comments/commentRss/302290.htmlhttp://www.aygfsteel.com/lyjjq/services/trackbacks/302290.html .btn { BORDER-RIGHT: #7b9ebd 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #7b9ebd 1px solid; PADDING-LEFT: 2px; FONT-SIZE: 12px; FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#cecfde); BORDER-LEFT: #7b9ebd 1px solid; CURSOR: hand; COLOR: black; PADDING-TOP: 2px; BORDER-BOTTOM: #7b9ebd 1px solid } .btn1_mouseout { BORDER-RIGHT: #7EBF4F 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #7EBF4F 1px solid; PADDING-LEFT: 2px; FONT-SIZE: 12px; FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#B3D997); BORDER-LEFT: #7EBF4F 1px solid; CURSOR: hand; COLOR: black; PADDING-TOP: 2px; BORDER-BOTTOM: #7EBF4F 1px solid } .btn1_mouseover { BORDER-RIGHT: #7EBF4F 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #7EBF4F 1px solid; PADDING-LEFT: 2px; FONT-SIZE: 12px; FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#CAE4B6); BORDER-LEFT: #7EBF4F 1px solid; CURSOR: hand; COLOR: black; PADDING-TOP: 2px; BORDER-BOTTOM: #7EBF4F 1px solid } .btn2 {padding: 2 4 0 4;font-size:12px;height:23;background-color:#ece9d8;border-width:1;} .btn3_mouseout { BORDER-RIGHT: #2C59AA 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #2C59AA 1px solid; PADDING-LEFT: 2px; FONT-SIZE: 12px; FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#C3DAF5); BORDER-LEFT: #2C59AA 1px solid; CURSOR: hand; COLOR: black; PADDING-TOP: 2px; BORDER-BOTTOM: #2C59AA 1px solid } .btn3_mouseover { BORDER-RIGHT: #2C59AA 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #2C59AA 1px solid; PADDING-LEFT: 2px; FONT-SIZE: 12px; FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#D7E7FA); BORDER-LEFT: #2C59AA 1px solid; CURSOR: hand; COLOR: black; PADDING-TOP: 2px; BORDER-BOTTOM: #2C59AA 1px solid } .btn3_mousedown { BORDER-RIGHT: #FFE400 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #FFE400 1px solid; PADDING-LEFT: 2px; FONT-SIZE: 12px; FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#C3DAF5); BORDER-LEFT: #FFE400 1px solid; CURSOR: hand; COLOR: black; PADDING-TOP: 2px; BORDER-BOTTOM: #FFE400 1px solid } .btn3_mouseup { BORDER-RIGHT: #2C59AA 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #2C59AA 1px solid; PADDING-LEFT: 2px; FONT-SIZE: 12px; FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#C3DAF5); BORDER-LEFT: #2C59AA 1px solid; CURSOR: hand; COLOR: black; PADDING-TOP: 2px; BORDER-BOTTOM: #2C59AA 1px solid } .btn_2k3 { BORDER-RIGHT: #002D96 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #002D96 1px solid; PADDING-LEFT: 2px; FONT-SIZE: 12px; FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#FFFFFF, EndColorStr=#9DBCEA); BORDER-LEFT: #002D96 1px solid; CURSOR: hand; COLOR: black; PADDING-TOP: 2px; BORDER-BOTTOM: #002D96 1px solid }

 

下載



強(qiáng)強(qiáng) 2009-11-13 23:37 發(fā)表評(píng)論
]]>
主站蜘蛛池模板: 鹤峰县| 南城县| 石阡县| 彰化市| 武功县| 平塘县| 广东省| 双流县| 万源市| 林甸县| 武强县| 若羌县| 县级市| 和平县| 新乡县| 崇仁县| 双江| 布拖县| 台前县| 平遥县| 河南省| 瑞金市| 三门峡市| 轮台县| 团风县| 巴中市| 乌苏市| 云和县| 遂宁市| 屏边| 泉州市| 花垣县| 咸丰县| 天全县| 丹巴县| 荥阳市| 泰兴市| 清流县| 昌平区| 勐海县| 陈巴尔虎旗|