编程(脚本)
Jul 3
轻量级 jQuery 看图插件 phZoom
[phZoom] 是一个小巧的jQuery看图插件.
==================================
当前版本: phZoom 1.23 RC
更新时间: 2011.11.05

使用方法和步骤:
1. 加载jQuery库(需1.4+)
2. 加载phZoom.css, 请保证压缩包内的两张小图片与phzoom.css同级目录
3. 加载phzoom.js, 请保证其加载于jQuery库之后
4. 调用接口:

$node.phzoom({
 // 此处为设置项, 可留空
});

请把 $node 改为所需的jQuery选择器, 如: $('a:has(img)')

不管如何调用, 请务必将调用代码包在一个DOM Ready方法内, 如:

$(function(){
// 此处为上面的调用接口
});

以下为插件设置选项, 注意大括号结束前不要逗号

{

 layOpacity:0.7,     // 遮罩层不透明度, 默认0.7即为70%不透明
 layDur:300,         // 遮罩层渐显的时间, 单位毫秒
 animDurA:300,       // 图片从原位飞到荧幕中间的时间, 单位毫秒
 animDurB:300,       // 图片从小到大的变化时间, 单位毫秒
 navColor:'#cf0',    // 上/下一张的文本颜色, 需要引号
 capColor:'#cf0',    // 大图底部标题与索引的文本颜色, 需要引号
 limitWidth:false    // 若设为true, 特大图将不会宽于窗口(保持宽高比)

}

Oct 21
输入文件内容后,用记事本打开,里面换行符都成了黑方格,其他正常,怎么解决呢?
在网上搜了一下,别人说将换行符"\n"替换为"\r\n"
qqEmail="itlife365.com\n" ;   // 旧的格式
qqEmail="itlife365.com\r\n" ; // 新的格式
Dec 2

JQuery获取和设置Select选项

<select name=sel onchange="bao(this.options[this.options.selectedIndex].value)">

  

获取Select :

  

 获取select 选中的 text :

   $("#ddlRegType").find("option:selected").text();

 获取select选中的 value:

  

   $("#ddlRegType ").val();

 获取select选中的索引:

     $("#ddlRegType ").get(0).selectedIndex;

  

设置select:

  

 设置select 选中的索引:

     $("#ddlRegType ").get(0).selectedIndex=index;//index为索引值

  设置select 选中的value:

    $("#ddlRegType ").attr("value","Normal“);

    $("#ddlRegType ").val("Normal");

    $("#ddlRegType ").get(0).value = value;

  设置select 选中的text:

var count=$("#ddlRegType option").length;

  for(var i=0;i<count;i++)  
     {           if($("#ddlRegType ").get(0).options[i].text == text)  
        {  
            $("#ddlRegType ").get(0).options[i].selected = true;  
         
            break;  
        }  
    } 

  

清空 Select:

$("#ddlRegType ").empty();

                       
Tags:
Nov 25
<script>
function getInfo()
{
var s = "";
s += " 网页可见区域宽:"+ document.body.clientWidth;
s += " 网页可见区域高:"+ document.body.clientHeight;
s += " 网页可见区域宽:"+ document.body.offsetWidth + " (包括边线和滚动条的宽)";
s += " 网页可见区域高:"+ document.body.offsetHeight + " (包括边线的宽)";
s += " 网页正文全文宽:"+ document.body.scrollWidth;
s += " 网页正文全文高:"+ document.body.scrollHeight;
s += " 网页被卷去的高(ff):"+ document.body.scrollTop;
s += " 网页被卷去的高(ie):"+ document.documentElement.scrollTop;
s += " 网页被卷去的左:"+ document.body.scrollLeft;
s += " 网页正文部分上:"+ window.screenTop;
s += " 网页正文部分左:"+ window.screenLeft;
s += " 屏幕分辨率的高:"+ window.screen.height;
s += " 屏幕分辨率的宽:"+ window.screen.width;
s += " 屏幕可用工作区高度:"+ window.screen.availHeight;
s += " 屏幕可用工作区宽度:"+ window.screen.availWidth;
s += " 你的屏幕设置是 "+ window.screen.colorDepth +" 位彩色";
s += " 你的屏幕设置 "+ window.screen.deviceXDPI +" 像素/英寸";
alert (s);
}
getInfo();
</script>
Nov 15

密码强度提示是最近流行的一个功能,但是99%的案例都忽略了检测机制。
基本上都是把字符分成四类:数字、小写英文、大写英文、符号,然后按照组合复杂度来直接判断强弱程度:
单一,是弱密码。
两两组合,是中密码。
超过两种组合,是强密码。
方案一
<SCRIPT language=javascript>    
  
    //CharMode函数    
    //测试某个字符是属于哪一类.    
    function CharMode(iN)   
    {    
        if (iN>=48 && iN <=57) //数字    
        return 1;    
        if (iN>=65 && iN <=90) //大写字母    
        return 2;    
        if (iN>=97 && iN <=122) //小写    
        return 4;    
        else    
        return 8; //特殊字符    
    }    
       
    //bitTotal函数    
    //计算出当前密码当中一共有多少种模式    
    function bitTotal(num)   
    {    
        modes=0;    
        for (i=0;i<4;i++)   
        {    
            if (num & 1) modes++;    
            num>>=1;    
        }    
        return modes;    
    }    
       
    //checkStrong函数    
    //返回密码的强度级别    
       
    function checkStrong(sPW)   
    {    
        if (sPW.length<=4)    
        return 0; //密码太短    
        Modes=0;    
        for (i=0;i<sPW.length;i++)   
        {    
            //测试每一个字符的类别并统计一共有多少种模式.    
            Modes|=CharMode(sPW.charCodeAt(i));    
        }    
        return bitTotal(Modes);    
    }    
       
    //pwStrength函数    
    //当用户放开键盘或密码输入框失去焦点时,根据不同的级别显示不同的颜色    
       
    function pwStrength(pwd)   
    {    
        O_color="#eeeeee";    
        L_color="#FF0000";    
        M_color="#FF9900";    
        H_color="#33CC00";    
        if (pwd==null||pwd=="")   
        {    
            Lcolor=Mcolor=Hcolor=O_color;    
        }    
        else  
        {    
            S_level=checkStrong(pwd);    
            switch(S_level)   
            {    
                case 0:    
                Lcolor=Mcolor=Hcolor=O_color;    
                case 1:    
                Lcolor=L_color;    
                Mcolor=Hcolor=O_color;    
                break;    
                case 2:    
                Lcolor=Mcolor=M_color;    
                Hcolor=O_color;    
                break;    
                default:    
                Lcolor=Mcolor=Hcolor=H_color;    
            }    
        }    
        document.getElementById("strength_L").style.background=Lcolor;    
        document.getElementById("strength_M").style.background=Mcolor;    
        document.getElementById("strength_H").style.background=Hcolor;    
        return;    
    }    
  
</SCRIPT>    
  
    <FORM name="form1" action=""><P>    
    输入密码:</P><P>   
    <INPUT onblur=pwStrength(this.value) onkeyup=pwStrength(this.value) type=password size=10 value="">    
    <BR>    密码强度: </P><P>   
    <TABLE style="DISPLAY: inline" borderColor=#cccccc height=23 cellSpacing=0 cellPadding=1 width=217 border=1>
 <TBODY>
 <TR align=middle bgColor=#eeeeee>
 <TD id=strength_L width="33%">弱</TD>
 <TD id=strength_M width="33%">中</TD>
 <TD id=strength_H width="33%">强</TD>
 </TR>
 </TBODY>
 </TABLE>    
    </P><P> </P><P> </P></FORM>   
<PRE></PRE>
方案二
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>密码</title>
<script type="text/javascript">
 function chkpwd(obj){
  var t=obj.value;
  var id=getResult(t);
  
  //定义对应的消息提示
  var msg=new Array(4);
  msg[0]="密码过短";
  msg[1]="密码强度差";
  msg[2]="密码强度良好";
  msg[3]="密码强度高";
  
  var sty=new Array(4);
  sty[0]=-45;
  sty[1]=-30;
  sty[2]=-15;
  sty[3]=0;
  
  var col=new Array(4);
  col[0]="gray";
  col[1]="red";
  col[2]="#ff6600";
  col[3]="Green";
  
  //设置显示效果
  var bImg="http://bbs.blueidea.com/attachments/2006/12/7/pwdlen_dSIPeEGQWxfO.gif";//一张显示用的图片
  var sWidth=300;
  var sHeight=15;
  var Bobj=document.getElementById("chkResult");

  Bobj.style.fontSize="12px";
  Bobj.style.color=col[id];
  Bobj.style.width=sWidth + "px";
  Bobj.style.height=sHeight + "px";
  Bobj.style.lineHeight=sHeight + "px";
  Bobj.style.background="url(" + bImg + ") no-repeat left " + sty[id] + "px";
  Bobj.style.textIndent="20px";
  Bobj.innerHTML="检测提示:" + msg[id];
 }
 
 //定义检测函数,返回0/1/2/3分别代表无效/差/一般/强
 function getResult(s){
  if(s.length < 4){
   return 0;
  }
  var ls = 0;
  if (s.match(/[a-z]/ig)){
   ls++;
  }
  if (s.match(/[0-9]/ig)){
   ls++;
  }
   if (s.match(/(.[^a-z0-9])/ig)){
   ls++;
  }
  if (s.length < 6 && ls > 0){
   ls--;
  }
  return ls
 }
</script>
<style type="text/css">
body{
 font-size:12px;
 font-family: Arial, Helvetica, sans-serif;
 margin:0;
}
form{
 margin:2em;
}
#chkResult{margin-left:53px;height:15px;}
</style>

</head>

<body>
<form name="form1">
 <label for="pwd">用户密码</label>
 <input type="password" name="pwd" onblur="chkpwd(this)" />
 <div id="chkResult"></div>
 <label for="pwd2">重复密码</label>
 <input type="password" name="pwd2" />
</form>

</body>

</html>

方案三
<html>
 <body>
  <form id="myform">
   <h1>Password Strength Meter - Demo</h1>
   <script type="text/javascript" s>
// Password strength meter v1.0
// Matthew R. Miller - 2007
// www.codeandcoffee.com
// Based off of code from  http://www.intelligent-web.co.uk

// Settings
// -- Toggle to true or false, if you want to change what is checked in the password
var bCheckNumbers = true;
var bCheckUpperCase = true;
var bCheckLowerCase = true;
var bCheckPunctuation = true;
var nPasswordLifetime = 365;

// Check password
function checkPassword(strPassword)
{
 // Reset combination count
 nCombinations = 0;
 
 // Check numbers
 if (bCheckNumbers)
 {
  strCheck = "0123456789";
  if (doesContain(strPassword, strCheck) > 0)
  {
          nCombinations += strCheck.length;
      }
 }
 
 // Check upper case
 if (bCheckUpperCase)
 {
  strCheck = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  if (doesContain(strPassword, strCheck) > 0)
  {
          nCombinations += strCheck.length;
      }
 }
 
 // Check lower case
 if (bCheckLowerCase)
 {
  strCheck = "abcdefghijklmnopqrstuvwxyz";
  if (doesContain(strPassword, strCheck) > 0)
  {
          nCombinations += strCheck.length;
      }
 }
 
 // Check punctuation
 if (bCheckPunctuation)
 {
  strCheck = ";:-_=+\|//?^&!.@$?*()%~<>{}[]";
  if (doesContain(strPassword, strCheck) > 0)
  {
          nCombinations += strCheck.length;
      }
 }
 
 // Calculate
 // -- 500 tries per second => minutes
     var nDays = ((Math.pow(nCombinations, strPassword.length) / 500) / 2) / 86400;
 
 // Number of days out of password lifetime setting
 var nPerc = nDays / nPasswordLifetime;
 
 return nPerc;
}
 
// Runs password through check and then updates GUI
function runPassword(strPassword, strFieldID)
{
 // Check password
 nPerc = checkPassword(strPassword);
 
  // Get controls
     var ctlBar = document.getElementById(strFieldID + "_bar");
     var ctlText = document.getElementById(strFieldID + "_text");
     if (!ctlBar || !ctlText)
      return;
     
     // Set new width
     var nRound = Math.round(nPerc * 100);
 if (nRound < (strPassword.length * 5))
 {
  nRound += strPassword.length * 5;
 }
 if (nRound > 100)
  nRound = 100;
     ctlBar.style.width = nRound + "%";
 
  // Color and text
  if (nRound > 95)
  {
   strText = "极佳";
   strColor = "#3bce08";
  }
  else if (nRound > 75)
  {
   strText = "很好";
   strColor = "orange";
 }
  else if (nRound > 50)
  {
   strText = "一般";
   strColor = "#ffd801";
  }
  else
  {
   strColor = "red";
   strText = "极差";
  }
 ctlBar.style.backgroundColor = strColor;
 ctlText.innerHTML = "<span style='color: " + strColor + ";'>" + strText + "</span>";
}
 
// Checks a string for a list of characters
function doesContain(strPassword, strCheck)
 {
     nCount = 0;
 
 for (i = 0; i < strPassword.length; i++)
 {
  if (strCheck.indexOf(strPassword.charAt(i)) > -1)
  {
          nCount++;
  }
 }
 
 return nCount;
}

</script>

   <b>Password:</b>
   <br />
   <input type="password" id="mypassword" name="mypassword" onkeyup="runPassword(this.value, 'mypassword');" />
   <br />
   <br />
   <b>Password Strength:</b>
   <br />
   <div style="width: 100px;">
    <div id="mypassword_text" style="font-size: 10px;"></div>
    <div id="mypassword_bar" style="font-size: 1px; height: 2px; width: 0px; border: 1px solid white;"></div>
   </div>
  </form>
 </body>
</html>

方案四

<html>
<title>密码强度计算-www.codefans.net</title>
<head>
<style type="text/css">
<!--
.text {
 height: 16px;
 width: 160px;
 border-top-width: 1px;
 border-right-width: 1px;
 border-bottom-width: 1px;
 border-left-width: 1px;
 border-top-style: solid;
 border-right-style: solid;
 border-bottom-style: solid;
 border-left-style: solid;
 border-top-color: #999999;
 border-right-color: #F0F0F0;
 border-bottom-color: #F0F0F0;
 border-left-color: #999999;
}
.style1 {font-size: 12px}
.m {
 background-image: url(image/m.gif);
 background-repeat: no-repeat;
 height: 15px;
 width: 158px;
}
.r {
 background-image: url(image/r.gif);
 background-repeat: no-repeat;
 height: 15px;
 width: 158px;
}
.z {
 background-image: url(image/z.gif);
 background-repeat: no-repeat;
 height: 15px;
 width: 158px;
}
.q {
 background-image: url(image/q.gif);
 background-repeat: no-repeat;
 height: 15px;
 width: 158px;
}
.style5 {font-size: 12px; color: #FF0000; }
.style6 {font-size: 12px; color: #F1F1F1; }
.style7 {font-size: 12px; color: #F1F1F1; }
.style8 {font-size: 12px; color: green; }
.style9 {font-size: 12px; color: red; }
-->
</style>
</head>
<script language=javascript>
function CharMode(iN){
 if (iN>=48 && iN <=57) //数字
  return 1;
 if (iN>=65 && iN <=90) //大写字母
  return 2;
 if (iN>=97 && iN <=122) //小写
  return 4;
 else
  return 8; //特殊字符
}
function bitTotal(num){
 modes=0;
 for (i=0;i<5;i++){
  if (num & 1) modes++;
  num>>>=1;
 }
 return modes;
}
function checkStrong(sPW){
 if (sPW.length<=5)
  return 0;  //密码太短
 Modes=0;
 for (i=0;i<sPW.length;i++){
  Modes|=CharMode(sPW.charCodeAt(i));
 }
 return bitTotal(Modes); 

function pwStrength(pwd,vImg,vImgs,ilength){
    if(pwd.length<=0){
      document.getElementById(vImgs).innerHTML="<span style=color:red;font-size:12px>"+16+"</span>";
    }
    else{
      document.getElementById(vImgs).innerHTML="<span style=color:red;font-size:12px>"+(16-pwd.length)+"</span>";
    }
 if (pwd==null||pwd==''){
  document.getElementById(vImg).className="m";
  //document.getElementById(ilength).className="style6";
 } 
 else{
  S_level=checkStrong(pwd);
  switch(S_level){
   case 0:
    document.getElementById(vImg).className="m";
    //document.getElementById(ilength).className="style6";
    break;
   case 1:
    document.getElementById(vImg).className="r";
    //document.getElementById(ilength).className="style7";
    break;
   case 2:
    document.getElementById(vImg).className="z";
    //document.getElementById(ilength).className="style8";
    break;
   default:
    document.getElementById(vImg).className="q";
    //document.getElementById(ilength).className="style9";
  }
 }
 return;
}
</script>
<body>
<div align="center">
  <p>    <br>
  </p>
  <form name="form1" method="post" action="">
    <table width="240" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="69" height="24">
        <div align="right" class="style1">密&nbsp;&nbsp;&nbsp; 码:</div></td>
        <td width="171"><div align="center">
          <input name="str1" type="password" class="text" onKeyUp="pwStrength(this.value,'img','imgs','ilength')" value="" maxlength="16" >
        </div></td>
      </tr>
      <tr>
        <td height="24">
        <div align="right" class="style1">密码强度:</div></td>
        <td height="19"><div align="center">
          <table width="160" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td align="center" valign="middle" class="m" id="img">
                    <table width="90%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="46%"><div align="right" class="style6" id="ilength"></div></td>
                        <td width="14%">&nbsp;</td>
                        <td width="40%" id="imgs"><span class="style5">16</span></td>
                      </tr>
                </table></td>
              </tr>
          </table>
        </div></td>
      </tr>
    </table>
  </form>
</div>
</body>
</html>

分页: 1/4 第一页 1 2 3 4 下页 最后页