Boolean和Date类型的扩展
(一)使用方式
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
function a()
{
var a = ['a','b','c','d'];
Array.add(a, 'e');
alert(a);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<input id="Button1" type="button" value="button" onclick="a();" />
</form>
</body>
</html>
关键部分ScriptManager 不能少,少了就用不了了.
(二)Boolean和Date类型的扩展
注:标注有[S]的为静态方法,无须实例化对象即可使用。
[S] Boolean.parse (value )
从字符串表示的布尔值解析成相应的Boolean类型。value参数必须为“true”或“false”二者之一,不区分大小写,且可以包含空格。
var b = Boolean.parse("true");
Date.format (format)
格式化字符串(区域设定无关)。
var d = new Date();
Sys.Debug.trace (d.format("dddd, dd MMMM yyyy HH:mm:ss"));
Date.localeFormat (format)
格式化字符串(区域设定相关)。使用Sys.CultureInfo.CurrentCulture得到区域属性。
var d = new Date();
Sys.Debug.trace (d.localeFormat("dddd, dd MMMM yyyy HH:mm:ss"));
[S] Date.parseLocale (value, formats)
从字符串表示的本地时间日期解析成相应的Date类型。使用Sys.CultureInfo.CurrentCulture得到区域属性。
Sys.Debug.trace (Date.parseLocale ("4/10/2001", "yyyy-MM-dd",
"MM/dd/yyyy"));
// Date.parseLocale will skip the first format here as invalid and use
// the second one. If it does not find an appropriate format,
// the function throws an exception.
[S] Date.parseInvariant (value, formats)
从字符串表示的区域无关时间日期解析成相应的Date类型。
Sys.Debug.trace (Date.parseInvariant ("4/10/2001", "yyyy-MM-dd",
"MM/dd/yyyy"));
// Date.parseInvariant will skip the first format here as invalid and use
// the second one. If it does not find an appropriate format,
// the function throws an exception.
支持的格式
- d: 缩写日期(e.g.: 02/17/2007):
- D: 完整日期(e.g: Saturday, 17 February 2007)
- t: 缩写时间(e.g.: 22:10)
- T: 完整时间(e.g.: 22:10:30)
- F: 完整时间日期(e.g.: Saturday, 17 February 2007 22:10:30)
- m (or M): 月和日(e.g.: February 17)
- s: 可排序的时间日期(e.g.: 2007-02-17T22:10:30)
- y (or Y): 年和月(e.g.: 2007 February)