友情提示:如果本网页打开太慢或显示不完整,请尝试鼠标右键“刷新”本网页!阅读过程发现任何错误请告诉我们,谢谢!! 报告错误
狗狗书籍 返回本书目录 我的书架 我的书签 TXT全本下载 进入书吧 加入书签

php程序设计简明教程(DOC格式)-第12章

按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!




texturea 元素输入的字符值改变时  

select 元素选项改变后  

 【例2…10 】onChange 事件的处理  

2…10。htm 源代码:  

  

      

           

           【例2…10 】onChange 事件的处理  

           

             function func2_10(textname;textvalue){  

                  alert(〃文本框〃+textname+〃的值被改成了〃+textvalue)  

             }  

           

      

      

         修改这些文本框中的值,看看会发生什么事情:  

           

           

      

  



                                                                                        

                                               onChange 事件  



                                         PHP 讲义    第  29  页  共  90  页  


…………………………………………………………Page 30……………………………………………………………

更多事件的详细介绍,请参考相关资料,在此不再赘述。  

 (3)常用JavaScript 内置对象的使用  

按数据类型可分为:字符串(string)对象、算术函数(math)对象、日期(Date)对象  

按使用时是否需要创建实例可分为:静态对象和动态对象。  

    静态对象:在引用其属性或方法时不需要为它创建实例,如string  (字符串);  

    动态对象:在引用其属性或方法时必须为它创建一个实例,如Date  (日期)。  

基本使用格式:对象名.属性名  

              对象名.方法名()  

1)串对象  

①属性。只有一个属性,即length。它表明了字符串中的字符个数,包括所有符号。例:  

②方法。共有 19 个,主要用于串在Web 页面中的显示、字体大小、字体颜色、字符的搜索以及字符的大小写 

转换等。  

其中,常用方法如下:  

〃Y  显示的控制方法    

 (a )fontsize(size)字体大小:作用同HTML 字体标签。    

语法:fontsize(size)    其中,1≤size≤7  

 (b)bold()粗体字  

 (c )Italics()斜体字  

〃Y  字体颜色;fontcolor(color)    

〃Y  大小写转换    

toLowerCase()小写转换,toUpperCase()大写转换。  

〃Y  取指定位置的字符:charAt(index),,0≤index≤串.长度…1 。  

〃Y  定位字符首次出现位置:indexOf(character,fromIndex)  

从指定formIndtx 位置开始,在串中搜索character 首出现的位置,0≤formIndex≤串.长度…1 。  

〃Y  定位字符末次出现位置:lastIndexOf(character,fromIndex)    

从指定formIndtx 位置开始,在串中搜索character 末次出现的位置,0≤formIndex ≤串.长度…1 。  

〃Y  取子串:substring(start;end)    

取下标为'start,end )的子串。  

若start》end,返回下标为'start,end )的子串;  

若start=end,返回空串;  

若start》end,返回下标为'start,end )的子串  

〃Y  上标:sup() ,作用同HTML 上标标签  

〃Y  下标:sub() ,作用同HTML 下标标签  

 【例2…11 】JavaScript 串对象的使用  

2…11。htm 源代码:  

  

  

  

  【例2…11 】JavaScript 串对象的使用  

  

  

    document。write(〃  【例2…11 】JavaScript 串对象的使用〃);  

    document。write(〃〃);  

      

    sa=〃hello〃;  

    sb=〃world〃;  

    document。write(〃 串sa:〃+sa);  

    document。write(〃〃);  



                                     PHP 讲义    第  30  页  共  90  页  


…………………………………………………………Page 31……………………………………………………………

      document。write(〃 串sb:〃+sb);  

      document。write(〃〃);  

          

      document。write(〃sa 的长度:〃+sa。length);  

      document。write(〃〃);  

        

      document。write(〃sa 设成7 号字体:〃+sa。fontsize(7));  

      document。write(〃〃);  

        

      document。write(〃sa 变红色:〃+sa。fontcolor(〃red〃));  

      document。write(〃〃);  

        

      document。write(〃sa 变大写:〃+sa。toUpperCase());  

      document。write(〃〃);  

        

      document。write(〃sa 中首次出现字母l 的下标位置=〃+ sa。indexOf(〃l〃;0));  

      document。write(〃〃);  

          

      document。write(〃sa 中末次出现字母l 的下标位置=〃+ sa。lastIndexOf(〃l〃;0));  

      document。write(〃〃);  

        

      document。write(〃sa。substring(0;2)=〃+ sa。substring(0;2));  

      document。write(〃〃);  

          

      document。write(〃sa。substring(2;0)=〃+ sa。substring(2;0));  

      document。write(〃〃);  

        

      document。write(〃sa。substring(2;2)=〃+ sa。substring(2;2));  

      document。write(〃〃);  

        

      document。write(〃sa。charAt(2)=〃+ sa。charAt(2));  

      document。write(〃〃);  

        

      document。write(〃sb 输出为上标:〃+sb。sup());  

      document。write(〃〃);  

        

      document。write(〃sb 输出为sa 的上标:〃+sa+sb。sup());  

      document。write(〃〃);  

        

      document。close();  

  

  

  

  



                                                         PHP 讲义    第  31  页  共  90  页  


…………………………………………………………Page 32……………………………………………………………

                                                                                      

                                                           

2 )系统函数  

JavaScript 中的系统函数又称内部方法。它提供了与任何对象无关的系统函数,使用这些函数不需创建任何实例; 

可直接用。  

方法名:eval  (字串表达式)  

作用:返回字符串表达式中的值  

例:  

test=eval(〃8+9+5/2〃);//test=19。5  

 (4 )窗口对象的使用  

有关输入可通过窗口(Window )对象来完成,而输出可通过文档(document )对象的方法来实现。  

 【例2…14 】窗口的简单例子  

2…14。htm 源代码:  

  

  

  

  【例2…14 】窗口的简单例子  

  

  

  

     var yourinput=window。prompt(〃请输入数据:〃;〃这里是默认数据〃);  

     document。clear();  

     document。write(〃你刚才输入的是:〃+yourinput);//输出流  

     document。close();//关闭输出流  

  

  

  



                                            PHP 讲义    第  
返回目录 上一页 下一页 回到顶部 0 0
未阅读完?加入书签已便下次继续阅读!
温馨提示: 温看小说的同时发表评论,说出自己的看法和其它小伙伴们分享也不错哦!发表书评还可以获得积分和经验奖励,认真写原创书评 被采纳为精评可以获得大量金币、积分和经验奖励哦!