关于JavaScript中判断滚动条到底部的说明

判断滚动条到底部,需要用到DOM的三个属性值,即scrollTop(滚动条在Y轴上的滚动距离)、clientHeight(内容可视区域的高度)、scrollHeight(容可视区域的高度加上溢出滚动的距离)。从这个三个属性可以看出来,滚动条到底部的条件即为:

scrollTop + clientHeight == scrollHeight

一、使用标准DOM方法:

// 定义滚动条判断方法
(function (window, undefined) {
    if (typeof (window.getScrollTop) != "function") {
        // 获取滚动条在Y轴上的滚动距离  
        window.getScrollTop = function () {
            var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
            if (document.body) {
                bodyScrollTop = document.body.scrollTop;
            }
            if (document.documentElement) {
                documentScrollTop = document.documentElement.scrollTop;
            }
            scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
            return scrollTop;
        };
    }
    if (typeof (window.getScrollHeight) != "function") {
        // 获取文档的总高度 
        window.getScrollHeight = function () {
            var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
            if (document.body) {
                bodyScrollHeight = document.body.scrollHeight;
            }
            if (document.documentElement) {
                documentScrollHeight = document.documentElement.scrollHeight;
            }
            scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
            return scrollHeight;
        };
    }
    if (typeof (window.getWindowHeight) != "function") {
        // 获取浏览器视口的高度 
        window.getWindowHeight = function () {
            var windowHeight = 0;
            if (document.compatMode == "CSS1Compat") {
                windowHeight = document.documentElement.clientHeight;
            } else {
                windowHeight = document.body.clientHeight;
            }
            return windowHeight;
        };
    }
})(window);

// 添加滚动事件
window.onscroll = function () {
    // 判断是否滚动条是否在底部
    if (getScrollTop() + getWindowHeight() == getScrollHeight()) {
        alert("滚动条在底部");
    }
};

二、使用jQuery框架方法:

// 定义jQuery对象
var $window = jQuery(window);
var $document = jQuery(document);
// 添加滚动事件
$window.scroll(function () {
    // 获取滚动条在Y轴上的滚动距离
    var scrollTop = $window.scrollTop();
    // 获取文档的总高度 
    var scrollHeight = $document.height();
    // 获取浏览器视口的高度 
    var windowHeight = $window.height();
    // 判断是否滚动条是否在底部
    if (scrollTop + windowHeight == scrollHeight) {
        alert("滚动条在底部");
    }
});

关于C#中读写Config文件配置数据的说明

在编写C#程序时,我们可以为每个应用程序创建一个默认的配置文件,一般命名为App.config,其在编译后将会生成一个以应用程序名称命名的并且后缀名为config的文件。我们可以将需要的配置信息记录在该文件的configuration/appSettings节点下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="key1" value="value1"/>
    <add key="key2" value="value2"/>
  </appSettings>
</configuration>

该文件实际是一个以configuration为根节点的XML文件,其除了可以用appSettings节点来配置一些常规的数据外,还可以使用其他很多节点来配置应用程序的相关运行数据和环境,如assemblyBinding(程序集绑定)、connectionStrings(连接字符串)等。对该配置文件的读写除了可以采用常规的读写XML文件方法外,我们还可以通过C#中的静态类ConfigurationManager(在System.Configuration.dll中)来管理配置数据。

一、读取配置数据:
使用ConfigurationManager类的AppSettings属性(或者ConnectionStrings属性)来读取配置文件数据:

// 使用key属性读取
string value1 = ConfigurationManager.AppSettings["key1"];
// 使用索引读取
string value2 = ConfigurationManager.AppSettings[1];

二、写入配置数据:
使用ConfigurationManager类的Configuration对象来写入配置文件数据:

// 获取可修改的配置对象
Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// 获取AppSettings的配置集合
KeyValueConfigurationCollection settings = configuration.AppSettings.Settings;
// 移除配置项
settings.Remove("key1");
settings.Remove("key2");
// 写入配置项
settings.Add("key", "value");
// 保存修改过的配置信息
configuration.Save(ConfigurationSaveMode.Modified);
// 刷新配置节点,使程序在下次检索时重新从磁盘中读取。
ConfigurationManager.RefreshSection("appSettings");

更多信息请参阅:ConfigurationManager 类 (System.Configuration)

关于WordPress中代码高亮插件SyntaxHighlighter所支持语言的说明

SyntaxHighlighter是应用在WordPress中的代码高亮插件,当我们在WordPress中编写文章时,使用它可以让我们安全地在文章中插入程序代码,并可以使代码高亮格式化显示,以下列出该插件所支持的代码类型:

actionscript3
bash
clojure
coldfusion
cpp
csharp
css
delphi
erlang
fsharp
diff
groovy
htmlscript
javascript
java
javafx
matlab(只支持关键字)
objc
perl
php
text(默认)
powershell
python
r
ruby
scala
sql
vb
xml

更多信息请参阅:Posting Source Code — Support — WordPress.com

关于SQLite中连接字符串的说明

SQLite在SQLite.NET中的连接字符串

基本

Data Source=C:/sqlite.db;Version=3;

SQLite-2版本不支持此方法

使用内存数据库

Data Source=:memory:;Version=3;New=True;

使用UTF-16编码

Data Source=C:/sqlite.db;Version=3;UseUTF16Encoding=True;

使用密码

Data Source=C:/sqlite.db;Version=3;Password=[password];

使用SQLite-3.3x版本之前的数据库格式

Data Source=C:/sqlite.db;Version=3;Legacy Format=True;

使用连接池

Data Source=C:/sqlite.db;Version=3;Pooling=True;Max Pool Size=100;

使用只读连接

Data Source=C:/sqlite.db;Version=3;Read Only=True;

将DateTime.Ticks作为datetime格式

Data Source=C:/sqlite.db;Version=3;DateTimeFormat=Ticks;

默认使用ISO8601日期时间格式

将GUID作为text格式

Data Source=C:/sqlite.db;Version=3;BinaryGUID=False;

存储GUID文本将使用更多的数据库空间。

指定缓存大小

Data Source=C:/sqlite.db;Version=3;Cache Size=2000;

以字节为单位

指定数据页大小

Data Source=C:/sqlite.db;Version=3;Page Size=1024;

以字节为单位

禁止在分布式事务中记录

Data Source=C:/sqlite.db;Version=3;Enlist=N;

禁止创建数据库

Data Source=C:/sqlite.db;Version=3;FailIfMissing=True;

限制数据库大小

Data Source=C:/sqlite.db;Version=3;Max Page Count=5000;

禁用日志文件

Data Source=C:/sqlite.db;Version=3;Journal Mode=Off;

使用日志文件

Data Source=C:/sqlite.db;Version=3;Journal Mode=Persist;

控制文件刷新

Data Source=C:/sqlite.db;Version=3;Synchronous=Full;

设置FULL后每次操作后自动刷新,否则由操作系统决定何时去刷新

SQLite在ADO.NET驱动中的连接字符串

标准

Data Source=C:/sqlite.db;Version=3;

对于SQLite-2.x版本使用Version=2,对于SQLite-3.x版本使用Version=3

创建新数据库

Data Source=C:/sqlite.db;Version=3;New=True;

使用数据库压缩

Data Source=C:/sqlite.db;Version=3;Compress=True;

指定缓存大小

Data Source=C:/sqlite.db;Version=3;Cache Size=3000;

使用UTF-8编码

Data Source=C:/sqlite.db;Version=3;UTF8Encoding=True;

使用UTF-16编码

Data Source=C:/sqlite.db;Version=3;UTF16Encoding=True;

SQLite在ODBC驱动中的连接字符串

标准

DRIVER=SQLite3 ODBC Driver;Database=C:/sqlite.db;LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;

SQLite在.NET Framework的ODBC驱动中的连接字符串

使用ODBC驱动

Driver=[驱动名称];OdbcKey1=[Value1];OdbcKey2=[Value2];

更多信息请参阅:SQLite connection strings – ConnectionStrings.com

关于SQLite中获取数据表Table信息的说明

在SQLite数据库中存在一张特殊的系统表sqlite_master(或者在一个临时数据库中被叫做sqlite_temp_master),该表存储了完整的数据库架构信息,表结构定义类似于如下方式:

create table sqlite_master(
    type text,
    name text,
    tbl_name text,
    rootpage integer,
    sql text
);

除了表sqlite_master自身外,在SQLite数据库中的每张数据表都会在sqlite_master表中记录一条数据,其记录的type字段值为“table”以表明该条数据记录的信息为数据表,而在name字段中则记录了数据表的名称,因此我们可以通过查询sqlite_master表来获取SQLite数据库中数据表的信息:

一、查询sqlite_master表数据:

select * from sqlite_master;

二、查询所有的数据表:

select name from sqlite_master where type = 'table';

三、通过查询已知名称的数据表数量来判断数据表是否存在:

select count(*) from sqlite_master where type = 'table' and name = '[数据表名]';

更多信息请参阅:File Format For SQLite Databases