存档:js/web

博客记忆

四月 23, 2010 | c/c++, js/web, linux, mysql, php, 心情杂记, 数学 | RSS 2.0

很长时间没有更新日志,大概有几个月了,疏于对知识的学习和管理,可能是跟工作有点忙有关系吧,经常顾着不顾那个,放弃了诸多的学习机会,
不过希望以后能恢复,时间是一种财富,能让你积淀更多的对知识的理解,同时也能验证更多的真理,譬如坚持才是硬道理,这两个月坚持的最好的一件事情还算是对自己花销的记录很分类,方法比较土,就是使用网易的邮箱里的一个小插件,有时候别人问你一个月能花多少钱?像我这种不扫一屋的人是一无所知的,统计了下发现对多的是花在了吃上和没周末的超市。
记得以前写博客都是从外面copy一堆东西,可能是自己的知识欠缺的太多,发现一篇技术文章就copy过来,沾沾自喜一番感觉很有成就感,后来发现好多牛人都是自己写博客,发现自己土了,而且写的都是超高技术含量,,而且现在基本上很多的知识获取都是从blog获得的,自己也曾在google reader里面follow了一堆,曾经每天早上9点到公司都花费10分钟时间,不过有点不好,开始没分类好,造成后来好多看的时候乱,杂乱无章的,挑出那种令你很满意的需要去甄选,所以有时候就懒的去看了。
不过一些东西一旦写下来还是能整理下自己的思维的。而且能做下备忘,所以以后需要把这个习惯坚持下去。今天写这个主要是想试试用vim写博客,用的是vimpress插件,下载地址在http://www.vim.org/scripts/script.php?script_id=1953,下来后直接解压到.vim下就可以了,修改blog.vim下的秘密用户还xmlrpc就可以了。ok,here,travel start。

没有评论 »

fck捕获事件支持ff,ie

十一月 21, 2008 | js/web | RSS 2.0

function FCKeditor_OnComplete( editorInstance )
{
 if (document.all) {      
    // IE
        editorInstance.EditorDocument.attachEvent(”onkeyup”, editor_keyup) ;
    } else {
       // other browser
       editorInstance.EditorDocument.addEventListener( ‘keyup’, editor_keyup, true ) ;
    }   
}

没有评论 »

熟悉ajax

九月 6, 2007 | js/web | RSS 2.0

<script type=”text/javascript”>
<!–
 var dt;
 function antiIdle() {
  //alert(’Start’);
  var b=document.getElementById(’b');
  b.onmousemove=antiIdle;
  b.onclick=antiIdle;
  b.onmousedown=antiIdle;
  b.onkeydown=antiIdle;
  window.clearTimeout(dt);
  dt=window.setTimeout(”location=’/'”,6000);
 }
 window.onload=antiIdle;
//–>
</script>
<body id=’b'>

// JavaScript Document
var xmlHttp;  //xmlhttp对象
var totalpage;
function createXmlHttp(){

try{
  xmlHttp=new XMLHttpRequest();
  }catch(trymicrosoft){
   try{
   xmlHttp=new ActiveXObject(”Msxml2.XMLHTTP”); 
   }catch(othermicrosoft){
    try{
     xmlHttp=new ActiveXObject(”Microsoft.XMLHTTP”);
     }catch(failed){
      xmlHttp=false;
      }
    }
   }
  if(!xmlHttp){
     alert(”Error initializing XMLHttpRequest!”);
     }
}
  
function callServer(page){
 createXmlHttp();
 var id=page?page:1;
 //alert(id);
 url=”response.asp?page=”+escape(id);
 xmlHttp.open(”GET”,url,true);
 xmlHttp.onreadystatechange=updatePage;
 xmlHttp.send(null);
 }   
 
 
function updatePage(){
 if(xmlHttp.readyState==4){
  if(xmlHttp.status==200){
   var response=xmlHttp.responseXml;
   var content=response.getElementsByTagName(”title”);
   var NumRecord=response.getElementsByTagName(”NumRecord”)[0].text; //总记录数
   var NumPage=response.getElementsByTagName(”NumPage”)[0].text;  //总页数
   totalpage=NumPage;
   //alert(NumRecord);
   //alert(NumPage);
   var showhtml=”";
   var showhtml=showhtml+”<ul>”;
   for(var i=0;i<content.length;i++){
    title=content[i].text;
   showhtml=showhtml+”<li>”+title+”< >” 
   
   }
   showhtml=showhtml+”< >”;
   document.getElementById(”showhtml”).innerHTML=showhtml;
   
   
   
   }
  }
 
 }
 alert(totalpage);

没有评论 »

练习正则

八月 14, 2007 | js/web, php, 数据结构算法 | RSS 2.0

<?
/*****************************************************
* Copyright     : [url]www.blog.163.com/liufabin66688[/url]
* FileName      : check
* Author        : 刘发宾
* NickName      : 小和尚
* Version       : v1.0
* Description   :验证
* CreatDate     : 2007-7
* HistoryEdit   : 历史修改记录
———- 第一次修改 ——————-     
        Author  :
        Date    :
        Summary :
————–  ————————     
*****************************************************/
class check
{
  /*
   @param:$str;
   @param:return,$str;
   return : $str;
   function :clear space
  */
  function trimstr($str)
  {
  if(strlen($str<1) return false;
  $str=preg_replace(”/(  | ){1,}/ “,”",$str);//替换全角
  return $str;
  }
    /*
   @param:$str;
   @param:$min;
   @param:$max
   @param:$type
   return bool
   function :check user
  */
  function CheckUser($str,$min=1,$max=20,$type=”$ENCN”)
  {
  trimstr($str);
  if(strlen($str)>$max||strlen($str)<$min) return false;
  switch($type)
    {
 case “EN”://英文
    return preg_match(”/^[a-zA-Z]+$/”,$str);
    break;
 case “ENNUM”://英文数字
  
    return preg_match(”/^[w]+$/”,$str);
    break;
  case “CN”://匹配中文
      return preg_match(”/^[x80-xff]+$/”,$str);
   break;
  case “ALL”://数字字母空格中文
    return preg_match(’/[x80-xff]*[x20]*[x30-x39]*[x41-x5a,x61-x7a]*/’,$str);
    break;
     
     default : return false;
    }
 
 
  }
  /*
  @param:$str;
  @param:$min;
  @param:$max;
  return :bool
  function:check password
  */
  function CheckPassword($str,$min=1,$max=20)
  {
    trimstr($str);
    if(strlen($str)>$max||strlen($str)<$min) return false;
 return preg_match(’/^[_w]+$/’);

 
  }
  /*
  @param:$str;
  @param:$type
  return :bool
  function :check telephone
  */
  function CheckTelePhone ($str,$type=”PH”)
  {
   trimstr($str);
   switch($type)
    {
 case “PH”: //普通电话
   return preg_match(’/^([0-9]{3}|0[0-9]{3})-[0-9]{7,8}$/’),$str);break;
 
 case “MO”:
    return preg_match(’/^(13[0-9])|159[0-9]{8}$/’),$str);break;
   
  default return false;
 }
 
  }
   /*
  @param:$str;
  @param:$type
  return :bool
  function :check time
  */
 function CheckTime($str,$type=”yyyy-mm-dd”)
 {
  trimstr(str);
  strtolower($type);
  switch($type)
  {
   case “yyyy-mm-dd”:
     $part=explode(”-”,$str);
  return checkdate($part[1],$part[2],$part[0]);
  break;
   case “yyyy/mm/dd”:
     $part=explode(”/”,$str);
  return checkdate($part[1],$part[2],$part[0]);
     break;
   case “ALL”:
    return preg_match(’/[d]{4}|[d][2][w]{1}[d]{1,2}[w][d]{1,2}[w]{0,4}/’);
   default $pattern = ‘/[d]{4}-[d]{1,2}-[d]{1,2}s[d]{1,2}:[d]{1,2}:[d]{1,2}/’;
    return preg_match($pattern, $time);
  }
 
 
 
 }
  /*
  @param:$str;
   return :bool
  function :check email
  */
 function CheckEmail($str)
{
return preg_match(’/([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)/’, $str);
 }
 /*
 @param:$str;
 return bool
 function: check url
 */
function CheckUrl($str)
{
return preg_match(’http://[w]+’,$str);

}

 

 

 

 

}

 

 

 

 

 

 

 


?> <?
 function  regex_play($in_strings,$in_regex)
 {
  if(!is_array($in_strings)||!is_string($in_regex))
  die(’bad parameters(array+string)</br>’);

  foreach($in_strings as $x=>$strval)
  {
  $found=ereg($in_regex,$strval,$matches);
  if($found)
  {
  echo “Array Index <b> $x</b>matches”;
  var_export($matches); echo “”$strval”<br/>”;
  
  }
  
  }
  
 echo “<br/1>”; 
 }
 
 
 
 
 
 $clothes=array(”shoes”,”pants”,”socks”,”jacket”,”cardigan”,”scarf”,”t-shirt”,”blouse”,”underpants”,”belt”,” hand bag”);
regex_play($clothes,’s$’);
 
 regex_play(array(”loser”,”looser”,”lser”,”looooser”),’lo{2,8}se’);
 $valid=ereg(”sgwgegdd”,’[[:alnum:]_-]{8,50}’);
 //if($ )
 echo ereg_replace(’shoe’,'cat’,'i like shoes and shoes like me’);
 echo ereg_replace(’$[0-9]+(.[0-9]{1,2})?’,'(lots of monery)’,'jony is paid $1500232.557 each yere’);
 echo “Preg_replace used time:”;
$start = time();
for($i=1;$i<=100;$i++) {
$str = “ssssssssssssssssssssssssssss”;
preg_replace(”/s/”,”",$str);
}
$ended = time()-$start;
echo $ended;
echo ”
ereg_replace used time:”;
$start = time();
for($i=1;$i<=100;$i++) {
$str = “ssssssssssssssssssssssssssss”;
ereg_replace(”s”,”",$str);
}
$ended = time()-$start;
echo $ended;
echo ”
str_replace used time:”;
$start = time();
for($i=1;$i<=100;$i++) {
$str = “sssssssssssssssssssssssssssss”;
str_replace(”s”,”",$str);
}
$ended = time()-$start;
echo $ended;
$str = “中文测试”;
preg_match_all(”/([x81-xfe][x40-xfe])/”, $str, $ch);
$patterns = array_unique($ch[0]);
print_r($patterns);
if (preg_match (”/php/i”, “PHP is the web scripting language of choice.”)) {
    print “A match was found.”;
} else {
    print “A match was not found.”;
}
/* 模式中的 b 表示单词的边界,因此只有独立的 “web” 单词会被匹配,
 * 而不会匹配例如 “webbing” 或 “cobweb” 中的一部分 */
if (preg_match (”/bwebb/i”, “PHP is the web scripting language of choice.”)) {
    print “A match was found.”;
} else {
    print “A match was not found.”;
}

if (preg_match (”/bwebb/i”, “PHP is the website scripting language of choice.”)) {
    print “A match was found.”;
} else {
    print “A match was not found.”;
}
preg_match(”/^(http://)?([^/]+)/i”,
    “http://www.php.net/index.html“, $matches);
$host = $matches[2];

//echo $host;
var_dump($matches);
preg_match(”/[^./]+.[^./]+$/”, $host, $matches);
echo “domain name is: {$matches[0]}”;

$lstr=’<a href=”http://ent.tom.com/1306/1310/2006627-197372.html” target=”_blank” class=list>妮可凯斯新婚牵手秀恩爱</a><br>
<a href=”http://ent.tom.com/1306/1362/2006627-197463.html” target=”_blank” class=list>传古巨基私下捞钱被雪藏</a> <a href=”http://ent.tom.com/1306/1362/2006627-197407.html” target=”_blank” class=list>传何炅孙国庆大打出手</a><br>
<a href=”http://ent.tom.com/1030/1565/2006627-197453.html” target=”_blank”>郝菲尔:早料到被淘汰</a> <a href=”http://ent.tom.com/1306/1362/2006627-197398.html” target=”_blank”>范冰冰”眼角整容图”曝光</a></td></tr>
</table>’;
if(preg_match_all(”/http://[a-zA-Z0-9][a-zA-Z0-9/._-]+[.html]/”,$lstr,$matches))
  foreach ($matches[0] as $url)
  echo $url.’<br>’;
else
  echo ‘没有合适’;
?>

 

没有评论 »

PHP+AJAX实现无刷新注册(带用户名实时检测)

七月 14, 2007 | js/web, php | RSS 2.0

(别人写的!)很多时候,我们在网上注册个人信息,在提交完页面后,总得等待页面刷新来告诉我们注册是否成功,遇到网络差的时候,如果注册了一大串的东西,在经过漫长的等待页面刷新后,得到的确是“您的用户名已被使用”或XXXXXXX不合法,我想大家的心情一定特别不爽,今天就介绍个AJAX实现页面不刷新注册+实时检测用户信息的简单注册程序,希望对大家有所帮助。好的,先看注册界面代码:

<table width=”831″ border=”0″ align=”center” cellpadding=”0″ cellspacing=”0″>

 <tr style=”display:none”>

 <td height=”35″ align=”center” > </td>

 </tr>

</table>

<table width=”100%” height=”256″ border=”0″ align=”center” cellpadding=”1″ cellspacing=”1″>

 <tr>

 <td width=”150″ align=”left” bgcolor=”#FFFFFF”> · 用户名称: </td>

 <td width=”310″ align=”center” bgcolor=”#FFFFFF”>

 <input type=”text” class=”inputtext” check’)” check’)”>

 <font color=”#FF6633″>*</font></td>

 <td align=”left” bgcolor=”#FFFFFF” > 4-16个字符,英文小写、汉字、数字、最好不要全部是数字。</td>

 </tr>

 <tr>

 <td width=”150″ align=”left” bgcolor=”#FFFFFF”> · 用户密码:</td>

 <td width=”310″ align=”center” bgcolor=”#FFFFFF”>

 <input type=”password” class=”inputtext” pwd’)” pwd’)”>

 <font color=”#FF6633″>*</font> </td>

 <td align=”left” bgcolor=”#FFFFFF” > 密码字母有大小写之分。6-16位(包括6、16),限用英文、数字。</td>

 </tr>

 <tr>

 <td width=”150″ align=”left” bgcolor=”#FFFFFF”> · 重复密码:</td>

 <td width=”310″ align=”center” bgcolor=”#FFFFFF”>

 <input type=”password” class=”inputtext” repwd’)” repwd’)”>

 <font color=”#FF6633″>*</font> </td>

 <td align=”left” bgcolor=”#FFFFFF” > 请再次输入登录密码。</td>

 </tr>

 </table>

当我们选定一个文本框后就会开始调用,现在我们看上面那个页面包含的ajaxreg.js文件的代码,里面就是包含了ajax框架和一些判断函数。

var http_request=false;

 function send_request(url){//初始化,指定处理函数,发送请求的函数

 http_request=false;

 //开始初始化XMLHttpRequest对象

 if(window.XMLHttpRequest){//Mozilla浏览器

 http_request=new XMLHttpRequest();

 if(http_request.overrideMimeType){//设置MIME类别

 http_request.overrideMimeType(”text/xml”);

 }

 }

 else if(window.ActiveXObject){//IE浏览器

 try{

 http_request=new ActiveXObject(”Msxml2.XMLHttp”);

 }catch(e){

 try{

 http_request=new ActiveXobject(”Microsoft.XMLHttp”);

 }catch(e){}

 }

 }

 if(!http_request){//异常,创建对象实例失败

 window.alert(”创建XMLHttp对象失败!”);

 return false;

 }

 http_request.onreadystatechange=processrequest;

 //确定发送请求方式,URL,及是否同步执行下段代码

 http_request.open(”GET”,url,true);

 http_request.send(null);

 }

 //处理返回信息的函数

 function processrequest(){

 if(http_request.readyState==4){//判断对象状态

 if(http_request.status==200){//信息已成功返回,开始处理信息

 document.getElementById(reobj).innerHTML=http_request.responseText;

 }

 else{//页面不正常

 alert(”您所请求的页面不正常!”);

 }

 }

 }

 function usercheck(obj){

 var f=document.reg;

 var username=f.username.value;

 if(username==”"){

 document.getElementById(obj).innerHTML=” <font color=red>用户名不能为空!</font>”;

 f.username.focus();

 return false;

 }

 else{

 document.getElementById(obj).innerHTML=”正在读取数据…”;

 send_request(’checkuserreg.php?username=’+username);

 reobj=obj;

 }

 }

 function pwdcheck(obj){

 var f=document.reg;

 var pwd=f.userpwd.value;

 if(pwd==”"){

 document.getElementById(obj).innerHTML=” <font color=red>用户密码不能为空!</font>”;

 f.userpwd.focus();

 return false;

 }

 else if(f.userpwd.value.length<6){

 document.getElementById(obj).innerHTML=” <font color=red>密码长度不能小于6位!</font>”;

 f.userpwd.focus();

 return false;

 }

 else{

 document.getElementById(obj).innerHTML=” <font color=red>密码符合要求!</font>”;

 }

 }

 function pwdrecheck(obj){

 var f=document.reg;

 var repwd=f.reuserpwd.value;

 if (repwd==”"){

 document.getElementById(obj).innerHTML=” <font color=red>请再输入一次密码!</font>”;

 f.reuserpwd.focus();

 return false;

 }

 else if(f.userpwd.value!=f.reuserpwd.value){

 document.getElementById(obj).innerHTML=” <font color=red>两次输入的密码不一致!</font>”;

 f.reuserpwd.focus();

 return false;

 }

 else{

 document.getElementById(obj).innerHTML=” <font color=red>密码输入正确!</font>”;

 }

 }

不难看出,数据是通过异步传输到checkuserreg.php接着回送回信息显示出来来达到实时检测用户名的目的,至于密码,只作了长度的实时判断,有兴趣的朋友可以扩充功能。来看下checkuserreg.php到底都做了什么:

<?php

 header(’Content-Type:text/html;charset=GB2312′);//避免输出乱码

 include(’inc/config.inc.php’);//包含数据库基本配置信息

 include(’inc/dbclass.php’);//包含数据库操作类

 $username=trim($_GET['username']);//获取注册名

 //———————————————————————————–

 $db=new db;//从数据库操作类生成实例

 $db->mysql($dbhost,$dbuser,$dbpassword,$dbname);//调用连接参数函数

 $db->createcon();//调用创建连接函数

 //———————————————————————————–

 $querysql=”select username from cr_userinfo where username=’$username’”;//查询会员名

 $result=$db->query($querysql);

 $rows=$db->loop_query($result);

 //若会员名已注册

 //———————————————————————————–

 if($rows){

 echo” <font color=red>此会员名已被注册,请更换会员名!</font>”;

 }

 //会员名未注册则显示

 //———————————————————————————–

 else{

 echo” <font color=red>此会员名可以注册!</font>”;

 }

 if($action==reg){

 $addsql=”insert into cr_userinfo

 values(0,’$username’,'$userpwd’,'$time’,50,1,’$userquestion’,'$useranswer’)”;

 $db->query($addsql);

 echo”<img src=images/pass.gif> <font color=red>恭喜您,注册成功!请点击<a href=login.php>这里</a>登陆!</font>”;

 }

 $db->close();//关闭数据库连接

?>

注释写的还算详细,大家应该都能看懂,再看信息合法后我们提交注册信息实现无刷新注册的PHP代码,senduserinfo.php:

<?php

 header(’Content-Type:text/html;charset=GB2312′);//避免输出乱码

 include(’inc/config.inc.php’);//包含数据库基本配置信息

 include(’inc/dbclass.php’);//包含数据库操作类

 $username=trim($_GET['username']);//获取注册名

 $userpwd=md5(trim($_GET['userpwd']));//获取注册密码

 $time=date(”Y-m-d”);

 

 //———————————————————————————–

 $db=new db;//从数据库操作类生成实例

 $db->mysql($dbhost,$dbuser,$dbpassword,$dbname);//调用连接参数函数

 $db->createcon();//调用创建连接函数

 //———————————————————————————–

 //开始插入数据

 //———————————————————————————–

 $addsql=”insert into cr_userinfo values(0,’$username’,'$userpwd’,'$time’,50,1,’$userquestion’,'$useranswer’)”;

 $db->query($addsql);

 echo”<img src=images/pass.gif> <font color=red>恭喜您,注册成功!请点击<a href=login.php>这里</a>登录!</font>”;

 

 $db->close();//关闭数据库连接

?>

没有评论 »

CSS自动换行

七月 14, 2007 | js/web | RSS 2.0

大家都知道连续的英文或数字能是容器被撑大,不能根据容器的大小自动换行,下面是 CSS如何将他们换行的方法!

对于div

  1. (IE浏览器)white-space:normal; word-break:break-all;这里前者是遵循标准。以下是引用片段:
    white-space:normal|pre|nowrap
    normal : 缺省值。文本自然换行。如果超过元素宽度,内容自然换到下一行。
    nowrap : 不允许换行。
    pre : 保留换行和空白。这个值只有当你声明了!DOCTYPE,且IE6以上版本才支持。
    #wrap { white-space:normal; width:200px; }
    或者
    #wrap { word-break:break-all; width:200px; } 
    eg.
    <div >ddd11111111111111111111111111</div>
    效果:可以实现换行.
  2. (Firefox浏览器)
    white-space:normal; word-break:break-all; overflow:hidden;
    同样的FF下也没有很好的实现方法,只能隐藏或者加滚动条,当然不加滚动条效果更好!
    #wrap {  white-space:normal;  width:200px;  overflow:auto;}
    或者
    #wrap {   word-break:break-all;  width:200px;  overflow:auto;}
    eg.
    <div id=”wrap”>ddd1111111111111111111111111111111111111111</div> 
    效果:容器正常,内容隐藏

对于table

  1. (IE浏览器)使用样式 table-layout:fixed; 以下是引用片段:
    table-layout: auto | fixed
    auto : 默认的自动算法。布局将基于各单元格的内容。表格在每一单元格读取计算之后才会显示出来。速度很慢
    fixed : 固定布局的算法。在这算法中,水平布局是仅仅基于表格的宽度,表格边框的宽度,单元格间距,列的宽度,而和表格内容无关

    eg.
    <style> .tb{table-layout:fixed} </style> <table class=”tbl” width=”80″>   <tr>    <td>abcdefghigklmnopqrstuvwxyz 1234567890   </td>   </tr> </table> 
    效果:可以换行
  2. (IE浏览器)使用样式table-layout:fixed与nowrap,eg.
    <style> .tb { table-layout:fixed }</style> <table class=”tb” width=”80″>   <tr>      <td nowrap>abcdefghigklmnopqrstuvwxyz 1234567890     </td>  </tr></table>
    效果:可以换行
  3. (IE浏览器)在使用百分比固定td大小情况下使用样式table-layout:fixed与nowrap
    <style> .tb{table-layout:fixed}</style> <table class=”tb” width=80>   <tr>     <td width=25% nowrap>abcdefghigklmnopqrstuvwxyz 1234567890     </td>     <td nowrap>abcdefghigklmnopqrstuvwxyz 1234567890    </td>   </tr> </table>
    效果:两个td均正常换行
  4. (Firefox浏览器)在使用百分比固定td大小情况下使用样式table-layout:fixed与nowrap,并且使用div, eg.
    <style> .tb {table-layout:fixed} .td {overflow:hidden;}</style> <table class=tb width=80>   <tr>     <td width=25% class=td nowrap>      <div>abcdefghigklmnopqrstuvwxyz 1234567890     </div>    </td>     <td class=td nowrap>      <div>abcdefghigklmnopqrstuvwxyz 1234567890     </div>    </td>  </tr></table>
    这里单元格宽度一定要用百分比定义
    效果:正常显示,但不能换行(注:在FF下还没有能使容器内容换行的好方法,只能用overflow将多出的内容隐藏,以免影响整体效果)

没有评论 »

javascript 反射

七月 14, 2007 | js/web | RSS 2.0

  今天看书学到的

function setStyle(_style)

  {

 var element=getElement();

element.style=_style;

 

 }

var style={

   color:#ffffff,

 backgroundColor:#ff0000;

borderWidth:2px;

}

but if we have set  style ,it will  voerdi

function setStyle (_style)

{

var element=getElement();

for(var p in _style)

{

element.style[p]=_style[p];

}

 

}

没有评论 »

可以做试卷的倒计时

七月 7, 2007 | js/web | RSS 2.0

网易世界杯时的倒计时代码,以前保存的,今天不小看到了再贴一下。好用!

代码比上次淘宝的还简单!

var now = new Date(”12/16/2006 ” + 20 + “:” + 42+ “:” + 12);

上面代码是系统当前时间

var urodz= new Date(”12/20/2006 00:00:00″);

上面是目标时间。

设置好这两个参数就可以用了<div class=”rightPublic”>
<span ></span>
</div>
<script language=”Javascript1.2″>
var now = new Date(”12/16/2006 ” + 20 + “:” + 42
+ “:” + 12);
function THINPIGServerTime(){
var urodz= new Date(”12/20/2008 00:00:00″);
now.setTime(now.getTime()+250);
days = (urodz – now) / 1000 / 60 / 60 / 24;
daysRound = Math.floor(days);
hours = (urodz – now) / 1000 / 60 / 60 – (24 * daysRound);
hoursRound = Math.floor(hours);
minutes = (urodz – now) / 1000 /60 – (24 * 60 * daysRound) – (60 * hoursRound);
minutesRound = Math.floor(minutes);
seconds = (urodz – now) / 1000 – (24 * 60 * 60 * daysRound) – (60 * 60 * hoursRound) – (60 * minutesRound);
secondsRound = Math.round(seconds);
//document.getElementById(”clock”).innerHTML = “<div class=time><div class=content><h2>”+0  + “</h2><h3>” + 0+ “:” + minutesRound + “:” + 0+”</h3></div></div>”;
document.getElementById(”clock”).innerHTML = “<div class=time><div class=content><h2>”+daysRound  + “天</h2><h3>” + hoursRound + “:” + minutesRound + “:” + secondsRound+”</h3></div></div>”;
}
setInterval(”THINPIGServerTime()”,250);
</script>

没有评论 »

2007年7月7日

七月 7, 2007 | js/web, php | RSS 2.0

    无论是在asp中还是php或者是.net、java中如果数据很多我们必须对其进行分页,如果每次都是老老实实地去写分页那是一件头痛并且是重复劳动的事情,所以我们写出了分页的类,方便快捷,省去了很多麻烦。

    但是在PHP中如果使用了smarty或别的模板技术,结合一些服务器端的分页类或客户端的分页js那更是一种省事的方法,不管什么表的数据分页只要一个sql语句,其它什么都不用管。

/*

函数名:getListDbCount

参数:$query (sql语句)

功能:返回符合参数sql语句的记录总数

*/

function getListDbCount($query){

 global $db;

 $row_count = 0;

 $rs = $db->get_one($query);

 if( $rs['count'] > 0 ){

  $row_count = $rs['count'];

 }

 return $row_count;

/*

函数名:getListDb

参数:$query (sql语句)

功能:返回符合参数sql语句的记录集(返回一个多维数组)

*/

function getListDb($query){

 global $db;

 $listdb=array();

 $res = $db->query($query);

 while($one = $db->fetch_array($res)) {

  $listdb[] = $one;

 }

 unset($one);

 return $listdb;

}

上面的函数中$db是一个mysql数据库操作类,其实就是mysql_fetch_array封装了一下,再用while循环把数据集赋到数组$listDb中。

有了上面两个东西那分页结合上次我写过的一个分页类就很容易了

分页类:http://www.soelin.cn/tec/apn/2005/11/57.asp

例如

$page=$_GET['page'];

$pagesize=10;

$rs_count = getListDbCount(”select count(*) as count from table”);

$list = new pageList($rs_count,1,$pagesize);

$startRow = $list->getStartRow();

$total=0;

$totalpage = 0;

$listdb=array();

if($rs_count>0) {

 $total=$rs_count;

 $totalpage = ceil($total/$pagesize);

 $listdb =  getListDb(”select * FROM table limit $startRow ,$pagesize”);

}

再用smarty把$listdb

$smarty->assign($listdb, $listdb);

这样就大功告成,不同表的数据分页都只需这样,唯一要做的就是把sql语句写一下。方便

当然更可以结合js在客户端展现分页形式。

没有评论 »

js 将某个按钮禁用5秒钟

七月 6, 2007 | js/web | RSS 2.0

<FORM action=reg.asp?action=apply method=post>
<INPUT type=submit value=”请认真查看<服务条款和声明>(10 秒后继续)” ></Form>

<SCRIPT language=javascript>

   var secs = 10;

   document.agree.agreeb.disabled=true;

   for(i=1;i<=secs;i++) {

       window.setTimeout(”update(” + i + “)”, i * 1000);
  

   }

 function update(num) {

   if(num == secs) {

       document.agree.agreeb.value =”同意并注册”;

       document.agree.agreeb.disabled=false;

   }

   else {

       printnr = secs-num;

       document.agree.agreeb.value = “请认真查看<服务条款和声明> (” + printnr +” 秒后继续)”;

 }

}

</SCRIPT>

没有评论 »