日历

« 2008-10-09  
   1234
567891011
12131415161718
19202122232425
262728293031 

最新来客

统计信息

  • 访问量: 996
  • 日志数: 15
  • 建立时间: 2008-02-22
  • 更新时间: 2008-03-26

RSS订阅

我喊 ~!·#¥%……&×()——+

我的最新日志

  • js位置

    2008-3-26

    网页可见区域宽  document.body.clientWidth 
    网页可见区域高  document.body.clientHeight 
    网页可见区域宽(包括边线的宽)  document.body.offsetWidth 
    网页可见区域高(包括边线的宽)  document.body.offsetHeight 
    网页正文全文宽  document.body.scrollWidth 
    网页正文全文高  document.body.scrollHeight 
    网页被卷去的高  document.body.scrollTop 
    网页被卷去的左  document.body.scrollLeft 
    网页正文部分上  window.screenTop 
    网页正文部分左  window.screenLeft 
    屏幕分辨率的高  window.screen.height 
    屏幕分辨率的宽  window.screen.width 
    屏幕可用工作区高度  window.screen.availHeight 
    屏幕可用工作区宽度  window.screen.availWidth 
  • js 中的this

    2008-3-21

    书上云:在ECMAscrīpt 中,要掌握的最重要的概念之一是关键字this的用法,它用在对象的方法中,关键字this总是指向调用该方法的对象, 例如:
    var ōCar = new Object;
    oCar.color = "red";
    oCar.showColor = function () {
        alert(this.color);  //outputs =  "red"
    };
    这里,关键字 this 用在对象的showColor() 方法中,在此环境中, this 等于 car.
    再一个例子:
    function showColor() {
        alert(this.color);
    }

    var oCar1 = new Object;
    oCar1.color = "red";
    oCar1.showColor = showColor;

    var oCar2 = new Object;
    oCar2.color = "blue";
    oCar2.showColor = showColor;

    oCar1.showColor();  //outputs "red"
    oCar2.showColor();  //outputs "blue"

    这里足以了解 this 是怎么用的了

    于是我试了如下例子:

    <scrīpt type="text/javascrīpt">

        function helloworld() {
            //new hello();
           hello();
        }

        function hello() {
            this.msg = "aaa";
        }
       
        function text() {
            alert(msg);
        }
    </scrīpt>

    <input type="button" ōnClick="helloworld();" value="helloworld">
    <input type="button" ōnClick="text();" value="text">

    注意,如果用 蓝色 的例子,按下 helloword按钮后再按 text按键 ,会弹出 “aaa" 这是没问题的
    但如果用 红色 例子,这再做,不会弹出 alert , 为什么呢?

    我觉得是因为,当我们用 new 时,hello就是一个新生成的对象,它有一个方法,就是hello(),还有一个属性,就是变量msg,这是,msg 就归 对象hello 的了。
    当直接调用方法 hello() 是,没有生成对象,那么此时hello()函数中的this
    这个this代表什么呢,我还不知道,只知道此时的msg就是全局变量了
  • js翻页显示图片小程序

    2008-3-21

    自己写的一个js翻页显示图片小程序,演示如下:
    http://oping.net.cn/index/js
    很粗糙,没有样子,显示的图片也没美女,眼光不行,呵呵

    我是在Zend framework 下做的,其实就就一个js代码,可以右键看下源码:

    <scrīpt type="text/javascrīpt">
    <!--
    var imgDisplay = new Object;
    imgDisplay.unitPage = 3;//第页 20 张图片
    imgDisplay.sumCount = 0;//总共图片数
    imgDisplay.pageCount = 0;//总共分多少页
    imgDisplay.currentIndex = 0;//当前第几张图,从 0 开始 偏移值
    imgDisplay.currentpage = 0;//当前第几页,从 0 开始
    imgDisplay.img = new Array(); //所有图片信息 this.img[页数][页内偏移][0:标题 1:路径]

    //初始化
    imgDisplay.init = function() {
     this.sumCount = document.getElementById("imgListCount").value;//得到总数
     this.pageCount = Math.ceil(this.sumCount / this.unitPage);
     
     var index = 0;
     for (i = 0; i < this.pageCount; i++)
     {
      imgInfoList = new Array();
      for (j = 0; j < this.unitPage && index < this.sumCount; j++)
      {
       imgInfo = new Array();
       imgInfo[0] = document.getElementById('imgTitle_' + index).value;//标题
       imgInfo[1] = document.getElementById('imgList_' + index).value;//路径
       imgInfoList[j] = imgInfo;
       
       index++;
      }
      this.img[i] = imgInfoList;
     }

     //显示html
     if (this.sumCount > 0)
     {
      this.initHtml();
      this.changeHtml();
     }
    }

    //初始化html
    imgDisplay.initHtml = function() {
     //下拉框
     var selectObj = document.getElementById("pages");
     for (i = 0; i < this.pageCount; i++)
     {
      selectObj.options[selectObj.options.length] = new Option("第 " + (i + 1) + " 页", i);
      //var varItem = new Option(objItemText,objItemValue);
            //objSelect.options.add(varItem);
     }
    }

    //显示html
    imgDisplay.changeHtml = function() {//alert(this.currentpage);
     //图片路径
     var imgObj = document.getElementById("img");
     imgObj.src = this.img[this.currentpage][this.currentIndex][1];//图片

     //下拉框
     var selectObj = document.getElementById("pages");
     selectObj.value = this.currentpage;


     var pageObj = document.getElementById("currentpage");
     pageObj.innerHTML = (this.currentpage + 1);

     var pagesObj = document.getElementById("pageCount");
     pagesObj.innerHTML = this.pageCount;

     var pageObj = document.getElementById("p_index");
     var strHtml = "";
     for (i = 0; i < this.unitPage && (i + this.unitPage * this.currentpage) < this.sumCount; i++)
     {
      if (i == this.currentIndex % this.unitPage)
      {
       strHtml += " <em>" + (i + 1) + "</em>";
      }
      else
      {
       strHtml += " <a ōnClick=\";pagedown(" + i + ")\">" + (i + 1) + "</a>";
      }
     }
     pageObj.innerHTML = strHtml;
    }

    imgDisplay.init();//初始化

    //运行
    function autoRun() {
     if (imgDisplay.currentIndex + imgDisplay.currentpage * imgDisplay.unitPage >= imgDisplay.sumCount - 1)
     {
      //前进已到最后一页
      imgDisplay.currentpage = 0 ;//当前页
      imgDisplay.currentIndex = 0;//当前偏移
     }
     else
     {
      imgDisplay.currentIndex++;

      //本页满,换下一页
      if (imgDisplay.currentIndex >= imgDisplay.unitPage)
      {
       imgDisplay.currentIndex = 0;
       imgDisplay.currentpage++;
      }
     }
     imgDisplay.changeHtml();
    }

    //定时
    //var iTimeoutId = null;
    var iTimeoutId = setInterval("autoRun()", 2000);

    //翻页动作
    function pagedown(id) {
     imgDisplay.currentIndex = Number(id);//当前偏移
     imgDisplay.changeHtml();
     return false;
    }

    //下拉框作用
    function selectCtrl() {
     var selectObj = document.getElementById("pages");
     imgDisplay.currentpage = Number(selectObj.value);
     imgDisplay.currentIndex = 0;//当前偏移 设为 0
     imgDisplay.changeHtml(); 
    }

    function onFirst() {
     imgDisplay.currentpage = 0 ;//当前页
     imgDisplay.currentIndex = 0;//当前偏移
     imgDisplay.changeHtml();
    }

    function onPrv() {
     if (imgDisplay.currentpage == 0 && imgDisplay.currentIndex == 0)
     {
      //当前第一张图
      imgDisplay.currentpage = imgDisplay.pageCount - 1 ;//当前页
      imgDisplay.currentIndex = imgDisplay.sumCount % imgDisplay.unitPage - 1;//当前偏移
     }
     else
     { 
      imgDisplay.currentIndex--;

      //本页满,换下一页
      if (imgDisplay.currentIndex < 0)
      {
       imgDisplay.currentIndex = imgDisplay.unitPage - 1;
       imgDisplay.currentpage--;
      }
     }
     imgDisplay.changeHtml(); 
    }

    function onPlay() {
     iTimeoutId = setInterval("autoRun()", 2000);
    }

    function onPause() {
     clearInterval(iTimeoutId);
    }

    function onStop() {
     clearInterval(iTimeoutId);
     onFirst();
    }

    function onNext() {
     autoRun();
    }

    function onLast() {
     imgDisplay.currentpage = imgDisplay.pageCount - 1;//当前页
     imgDisplay.currentIndex = imgDisplay.sumCount % imgDisplay.unitPage - 1;//当前偏移
     imgDisplay.changeHtml();
    }
    //-->
    </scrīpt>

  • css学习

    2008-3-21

    link href="css/style.css" rel="stylesheet" type="text/css">
    这里的 rel="stylsheet" 表示的意思是 是告诉浏览器你link 进来的是个样式文件

    首先,link标签是用于当前文档引用外部文档的,其次,这个标签的rel属性用于对象和链接目标间的关系,说白了就是指明你链接进来的对象是个什么东西的,具体的值及其所表示的关系如下:
    Alternate:
    Appendix:
    Bookmark:
    Chapter:
    Contents:
    Copyright:
    Glossary:
    Help:
    Index:
    Next:
    Offline:
    Prev:
    Section:
    Prev:
    Section:
    Shortcut:
    Start:
    Stylesheet:
    Subsection:

     

  • 日期下拉框(简单)

    2008-3-17

    自己写的日期下拉框,简单至极,放在这里,以便自己后用

    <input type="hidden" id="date_y" name="date_y" value="2008"/>
    <input type="hidden" id="date_m" name="date_m" value="3" />
    <input type="hidden" id="date_d" name="date_d" value="17" />

    <select name="birthYear" id="birthYear" ōnchange="datatmp.onclick();">
    </select>
    <select name="birthMonth" id="birthMonth" ōnchange="datatmp.onclick();">
    </select>
    <select name="birthDay" id="birthDay">
    </select>  
    <scrīpt language="javascrīpt">
    //日期联动
    function DateSelect(iyear, imonth, iday) {
        this.currentTime = new Date();
        
        this.year = iyear;
        this.month = imonth;
        this.day = iday;
       
        this.yearObj = document.getElementById("birthYear");
        this.monthObj = document.getElementById("birthMonth");
        this.dayObj = document.getElementById("birthDay");
       
        this.MinYear = 1930;
        this.MaxYear = this.currentTime.getFullYear();//得到今年
       
        this.init = function() {
            this.drawYear();
            this.yearObj.value = this.year;
           
            this.drawMonth();
            this.monthObj.value = this.month;
           
            this.drawDay();
            this.dayObj.value = this.day;
        }
       
        this.drawYear = function() {
            for (i = this.MaxYear; i >= this.MinYear; i--)
            {
                this.yearObj.options[this.yearObj.length] = new Option(i + " 年", i);
            }
        }
       
        this.drawMonth = function() {
            for (i = 1; i <= 12; i++)
            {
                this.monthObj.options[this.monthObj.length] = new Option(i + " 月", i);
            }
        }
       
        this.drawDay = function() {
            for(i = 1; i <= new Date(this.year , this.month , 0).getDate() ; i++)
            {
                this.dayObj.options[this.dayObj.length] = new Option(i + " 日", i);
            }
        }
       
        this.onclick = function() {
            this.year = document.getElementById("birthYear").value;
            this.month = document.getElementById("birthMonth").value;
            this.drawDay();
        }
    }

    var datatmp = new DateSelect(document.getElementById('date_y').value, document.getElementById('date_m').value, document.getElementById('date_d').value);
    datatmp.init();
    </scrīpt>
     
  • JS操作select相关方法:新增 修改 删除 选中 清空 判断存在

    2008-3-13

    -------------------------------------------
    //1.判断select选项中 是否存在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选项中 加入一个Item
    function jsAddItemToSelect(objSelect,objItemText,objItemValue)
    {
         //判断是否存在
         if(jsSelectIsExitItem(objSelect,objItemValue))
         {
             alert("该Item的Value值已经存在");
         }
         else
         {
             var varItem = new Option(objItemText,objItemValue);
    //       objSelect.options[objSelect.options.length] = varItem;
             objSelect.options.add(varItem);
             alert("成功加入");
         }  
    }

    //3.从select选项中 删除一个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中 不存在该项");
         }  
    }

    //4.修改select选项中 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中 不存在该项");
         }  
    }
          
    //5.设置select中text="paraText"的第一个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出结果
         if(isExit)
         {
             alert("成功选中");          
         }
         else
         {
             alert("该select中 不存在该项");
         }  
    }

    //6.设置select中value="paraValue"的Item为选中
    //document.all.objSelect.value = objItemValue;

    //7.得到select的当前选中项的value
    //var currSelectValue = document.all.objSelect.value;

    //8.得到select的当前选中项的text
    //var currSelectText = document.all.objSelect.options[document.all.objSelect.selectedIndex].text;

    //9.得到select的当前选中项的Index
    //var currSelectIndex = document.all.objSelect.selectedIndex;

    10.清空select的项
    // document.all.objSelect.options.length = 0; 

  • ajax 初学

    2008-3-06

    这两天看上了ajax,一个听起来让我很晕的东西
    下面是我找到几个网页:

    http://tech.51cto.com/art/200511/11557.htm  ajax技术简介

    http://tech.51cto.com/art/200511/11565.htm ajax技术入门

    http://tech.51cto.com/art/200511/11791.htm ajax技术总汇

     

  • zend框架关于基地址

    2008-3-05

    今天发现自己原来上当啊,郁闷啊……

     在一开始看zend框架时,感觉好象谁告诉我就入口文件(index.php)一定要放在网站的有基地址上!
    然后我就累不拉急的把 htdocs文件夹 (我用的是xampp安装包安装的,据说这个就是基地址的目录,呵) 下的所有文件都移走了,然来把zend的请进来,一试,成功了,呵呵,心里还老高兴了。

    后来发现这样的话,我这台电脑不是只能有一个网站了吗?因为所有的都是从这个zend里的index.php开始的啊?不爽,上网搜了一圈,功夫不负 search 人!给我找到了,哈哈,
    基本做法是这样的:
    1.将你的网站文件移到你想的文件夹下,如 zend

    2. 在C:\WINDOWS\system32\drivers\etc\hosts 加一个域名, 如

    .......
    127.0.0.1 zendhost

    其实也就是本地解析一个域名了

    3.在\apache\conf\httpd.conf 文件的最后加上:
    ............
    NameVirtualHost 127.0.0.1
    <VirtualHost 127.0.0.1>
            ServerName zendhost
            DocumentRoot D:\xampp\htdocs\zend
            RewriteEngine On
    </VirtualHost>

    OK,重启,在地址栏里输入:zendhost 回车,搞定爽啊,

    终于可以了,可是可笑的就在这里,今天从同事里那才现在。原来,本来就没有那有复杂,其实任意放在一个文件夹下,在地址栏里输:如 127.0.0.1/zendhost 就可以了,呵呵,我真是苯啊!我后来再看了一下代码,原来是我在 index.php 里多加了一句话:

    $controller->setBaseUrl('/'); 所以所有的请来都转到根目录了!

     

  • zend历程 之 多模块控制器

    2008-3-05

    zend framework 作为构架, 模型-视图-控制器 (MVC)是重要的一个亮点,这控制器让我这样的初学者一时很头痛,反正我也搞不懂它是怎么转来转去了,我就理解为:
    控制器就是保存在 controller 文件夹下的文件,并且这些文件都是继承了 Zend_Controller_Action 的类,对了,这就是ZF中的控制器了(不能理解,呵呵)如:文件/controller/fooController.php

    <?php
    class FooController extends Zend_Controller_Action
    {
        var $views;  
        var $data;   
        public function init()
        {
            //拿回注册过的对象
            $this->views = Zend_Registry::get('views');
        }
        public function testAction()
        {
           echo "hello world!";
       }
    }
    那么现在访问 http://localhost/foo/test 就会显示 hello world 。ZF将url中的 foo 解释为控制器名,也就是我们这个
    fooController.php 文件了,将url中的test解释为控制器中的方法,也就是我们写的 public function testAction() 函数了,(嗯,这个不难!)

    接下来就是这篇文章的重点了:
    因为,从上面可以知道,这样做的结果是所有的控制器文件都在同一个文件夹下(
    controller ),少还可以,多了就有点乱了,而且,有时要分不同的模块,我们并不想所有的都放在一起,这就要分模块(也就是放在不同的文件夹下了)。
    zend framework 手册上有说到:(如下)
    // Set the default controller directory:
    $front->setControllerDirectory('../application/controllers');
    
    // Set several module directories at once: $front->setControllerDirectory(array(  'default' => '../application/controllers',
    'blog' => '../modules/blog/controllers',
    'news' => '../modules/news/controllers', )); // Add a 'foo' module directory: $front->addControllerDirectory('../modules/foo/controllers', 'foo');
    说明一下,也就是我们在 index.php 中,设定前端路由器的工作目录的那一段代码
    从中可以看,可以建立不同的文件夹,如 /modules/blog/controllers 将其定义为
    模块 blog ,以 blog 为模块命名
    我试了下,在 /modules/blog/controllers 中创建文件blogdomController.php
    内容如下:
    <?php class BlogdomController extends Zend_Controller_Action { public function indexAction() { echo 'blogDom'; } public function testAction()
    { echo 'blog test';
    }
    }
    ?> 用:http://localhost/blog/blogdom/test 试了一把,预想应该是显示 blog test 吧 结果报错了,一看,原来在模块中的控制器有类命名在,要在前面加上
    模块名_
     也就是这样: class Blog_BlogdomController extends Zend_Controller_Action{ 现在,再输入
    http://localhost/blog/blogdom/test 就可以看见 blog test 了。这里 ,url中的blog 被解释为模块名了。
    那现在问题又出现了,当 控制器名 和 模块名 重名时,会怎么样呢? 我也试了,当重名时,会以模块名这先! 打完收工!
  • zend历程 之 初认控制器

    2008-3-05

    从入门PHP的第二个星期,就开是接触Zend framework了,可是,后来就放了。当时没有做下笔记,接着就什么都忘了,回悔啊,现在重新学过吧!
    今天要看的是控制器,这玩意太大,我也只是看看皮毛,由浅入深吧!
    下面是一个简单的控制器:

     class helloController extends Zend_Controller_Action
    {
        function indexAction()
        {
            echo "hi, this is my helloworld";
        }

        function testAction()
        {
            $var1 = $this->_getParam("var");
            echo "hello".$book_id;
        } 

       

        function __call($action,$args){
            $this->_redirect('/hello');
        }

    }

    运行结果是这样的:

    http://localhost/hello/test/var/world 会显示 hellowrold

    http://localhost/hello/netaction 时,会显示 hi, this is my helloworld

     

    其实我想说明的也就上面分色的两点:

    :在Zend中,我有接收参数,不管是 post 还是 get 的,只要用 如:

    $this->_getParam("var");

    的形式即可,

    final protected function _getParam($paramName, $default = null) 是控制器的私有方法,它还要可是带第二个参数,作为默认值,当没有得到你想要的参数时,返回这个默认值。

     

    :这个函数的目的为是,当访问的方法不存在时,自己转到一个地址(这里就是:http://localhost/hello 了)

     

Open Toolbar