使用第三方库

一般用户可忽略本节内容。

本节内容适合已经掌握JavaScript和CSS,希望使用第三方JavaScript库的用户。

使用第三方的Javascript库和使用本地库并没有差别,下面是一个使用jQuery库的例子。

1、在"d:\web"目录下,建立一个子目录lib,在这个子目录中新建一个文本文件,文件名为"test.js",文件内容为:

$(document).ready(function(){
    $('button').click(function(){
        $('div').animate({left:'250px'});
    });
});

2、HttpRequest事件代码设置为,在有变化的地方,我加上了注释:

Dim fl As String = "d:\web\" & e.path
If
filesys.FileExists(fl)
    Dim idx As Integer = fl.LastIndexOf(".")
    Dim ext As String  = fl.SubString(idx)
    Select Case ext
        Case ".jpg",".gif",".png",".bmp",".wmf",".js",".css"
            e.WriteFile(fl)
    End
Select
Else

    Dim html As String = <![CDATA[
    <!doctype html>
    <html>
    <head>
    <meta charset='utf-8'>
    <title>jQuery
测试</title>
    <script src='https://libs.baidu.com/jquery/1.10.2/jquery.min.js'></script>
    <script src='./lib/test.js'></script>
    </head>
    <body>
    <button>
开始动画</button><br/><br/>
    <div style='background:#98bf21;height:100px;width:100px;position:absolute;'>
    </body>
    </html>
    ]]>
.Value 
 
    e.WriteString(html)
End
If

在浏览器显示的结果如下,单击“开始动画”按钮,绿色方框会移动:


本页地址:http://www.foxtable.com/mobilehelp/topics/0018.htm