[WebMethod]
[ScriptMethod(UseHttpGet = true )]
public DateTime GetServerTime()
{
HttpCachePolicy cache = HttpContext.Current.Response.Cache;
cache.SetCacheability(HttpCacheability.Private);
cache.SetExpires(DateTime.Now.AddSeconds((double)10));
FieldInfo maxAgeField = cache.GetType().GetField(
"_maxAge", BindingFlags.Instance | BindingFlags.NonPublic);
maxAgeField.SetValue(cache, new TimeSpan(0, 0, 10));
return DateTime.Now;
}
粗体部分可以修改Response中Header的设置Cache-Control public, max-age=10
[ScriptMethod(UseHttpGet = true )]
public DateTime GetServerTime()
{
HttpCachePolicy cache = HttpContext.Current.Response.Cache;
cache.SetCacheability(HttpCacheability.Private);
cache.SetExpires(DateTime.Now.AddSeconds((double)10));
FieldInfo maxAgeField = cache.GetType().GetField(
"_maxAge", BindingFlags.Instance | BindingFlags.NonPublic);
maxAgeField.SetValue(cache, new TimeSpan(0, 0, 10));
return DateTime.Now;
}
引用: http://www.cnblogs.com/JeffreyZhao/archive/2007/07/02/client_side_caching_for_script_method_access.html
2、在表格中插入一个行
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
< head runat ="server" >
< title > 无标题页 </ title >
< script language ="javascript" type ="text/javascript" >
function insertRow()
{
var number = Math.floor(Math.random()*10+1);//1~10随机数
var t = document.getElementById('myTable');
var newRow = t.insertRow(-1);//表示在最后一行插入新行
var newCell1 = newRow.insertCell();
newCell1.height = "20px";
newCell1.innerHTML = "<input type='text' id='test" + number +"' />";
var newCell2 = newRow.insertCell();
newCell2.height = "20px";
newCell2.innerHTML = "<input type='button' value='添加新行' οnclick='insertRow()' id='btn" + number + "' />";
}
</ script >
</ head >
< body >
< form id ="form1" runat ="server" >
< div >
< table id ="myTable" >
< tr >
< td >
< input type ="text" />
</ td >
< td >
< input type ="button" value ="添加新行" onclick ="insertRow()" />
</ td >
</ tr >
</ table >
</ div >
</ form >
</ body >
</ html >
< head runat ="server" >
< title > 无标题页 </ title >
< script language ="javascript" type ="text/javascript" >
function insertRow()
{
var number = Math.floor(Math.random()*10+1);//1~10随机数
var t = document.getElementById('myTable');
var newRow = t.insertRow(-1);//表示在最后一行插入新行
var newCell1 = newRow.insertCell();
newCell1.height = "20px";
newCell1.innerHTML = "<input type='text' id='test" + number +"' />";
var newCell2 = newRow.insertCell();
newCell2.height = "20px";
newCell2.innerHTML = "<input type='button' value='添加新行' οnclick='insertRow()' id='btn" + number + "' />";
}
</ script >
</ head >
< body >
< form id ="form1" runat ="server" >
< div >
< table id ="myTable" >
< tr >
< td >
< input type ="text" />
</ td >
< td >
< input type ="button" value ="添加新行" onclick ="insertRow()" />
</ td >
</ tr >
</ table >
</ div >
</ form >
</ body >
</ html >
3、附录 B:使用 Internet Explorer 检测 .NET Framework 3.0 的示例脚本
下实例显示了在浏览器中运行的 JavaScript 程序如何检测 .NET Framework 3.0 是否正在运行。该脚本将搜索用户代理字符串,并基于搜索结果显示状态消息。
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< title > Test for NET Framework 3.0 </ title >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< script type ="text/javascript" language ="JavaScript" >
<!--
var RequiredFXVersion = "3.0.04131.06";
function window::onload()
{
var foundVer = CheckRequiredFXVersion(RequiredFXVersion);
if (foundVer != null)
{
result.innerHTML = "此计算机有正确版本的 .NET Framework:" + foundVer + "."+ "<br/>"
+ "此计算机的 userAgent 字符串为:" + navigator.userAgent + "。";
}
else
{
result.innerHTML = "此计算机没有正确版本的
.NET Framework。<br/>"
+ "<a href='http://msdn.microsoft.com/windowsvista/default.aspx'>单击此处</a> "
+ "立即获得 .NET Framework 3.0。<br>"
+ "此计算机的 userAgent 字符串为:" + navigator.userAgent + "。";
}
}
//
//从用户代理字符串中检索可用版本
//并检查它们是否与所需版本相匹配。
//
function CheckRequiredFXVersion(requiredVersion)
{
var userAgentString = navigator.userAgent.match(/\.NET CLR[ .][0-9.]+/g);
if (userAgentString != null)
{
var i;
for (i = 0; i < userAgentString.length; ++i)
{
var ver = userAgentString[i].slice(9);
if (CheckVersion(requiredVersion, ver))
return ver;
}
}
return null;
}
//
//检查某个特定版本是否为所需版本。
//
function CheckVersion(requiredVersion, ver)
{
requiredVersion = requiredVersion.split(".");
ver = ver.split(".");
//主要版本号必须严格匹配。
if (requiredVersion[0] != ver[0])
return false;
//次要版本号/版号必须不低于所需版本。
var i;
for (i = 1; i < requiredVersion.length && i < ver.length; i++)
{
if (new Number(ver[i]) < new Number(requiredVersion[i]))
return false;
}
return true;
}
-->
</ script >
</ head >
< body >
< div id ="result" />
</ body >
</ html >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< title > Test for NET Framework 3.0 </ title >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< script type ="text/javascript" language ="JavaScript" >
<!--
var RequiredFXVersion = "3.0.04131.06";
function window::onload()
{
var foundVer = CheckRequiredFXVersion(RequiredFXVersion);
if (foundVer != null)
{
result.innerHTML = "此计算机有正确版本的 .NET Framework:" + foundVer + "."+ "<br/>"
+ "此计算机的 userAgent 字符串为:" + navigator.userAgent + "。";
}
else
{
result.innerHTML = "此计算机没有正确版本的
.NET Framework。<br/>"
+ "<a href='http://msdn.microsoft.com/windowsvista/default.aspx'>单击此处</a> "
+ "立即获得 .NET Framework 3.0。<br>"
+ "此计算机的 userAgent 字符串为:" + navigator.userAgent + "。";
}
}
//
//从用户代理字符串中检索可用版本
//并检查它们是否与所需版本相匹配。
//
function CheckRequiredFXVersion(requiredVersion)
{
var userAgentString = navigator.userAgent.match(/\.NET CLR[ .][0-9.]+/g);
if (userAgentString != null)
{
var i;
for (i = 0; i < userAgentString.length; ++i)
{
var ver = userAgentString[i].slice(9);
if (CheckVersion(requiredVersion, ver))
return ver;
}
}
return null;
}
//
//检查某个特定版本是否为所需版本。
//
function CheckVersion(requiredVersion, ver)
{
requiredVersion = requiredVersion.split(".");
ver = ver.split(".");
//主要版本号必须严格匹配。
if (requiredVersion[0] != ver[0])
return false;
//次要版本号/版号必须不低于所需版本。
var i;
for (i = 1; i < requiredVersion.length && i < ver.length; i++)
{
if (new Number(ver[i]) < new Number(requiredVersion[i]))
return false;
}
return true;
}
-->
</ script >
</ head >
< body >
< div id ="result" />
</ body >
</ html >
如果成功搜索到字符串“.NET Framework 3.0”,将显示以下消息:
此计算机有正确版本的 .NET Framework:3.0.04131.06。
此计算机的 userAgent 字符串为:Mozilla/4.0(可兼容;MSIE 6.0;
Windows NT 5.1;SV1;.NET CLR 1.1.4322;.NET CLR 2.0.50727;.NET CLR 3.0.04131.06)。
此计算机的 userAgent 字符串为:Mozilla/4.0(可兼容;MSIE 6.0;
Windows NT 5.1;SV1;.NET CLR 1.1.4322;.NET CLR 2.0.50727;.NET CLR 3.0.04131.06)。
否则,会显示以下消息:
此计算机没有正确版本的 .NET Framework。
单击此处立即获得 .NET Framework 3.0。
此计算机的 userAgent 字符串为:Mozilla/4.0(可兼容;MSIE 6.0;
Windows NT 5.1;SV1;.NET CLR 1.1.4322;InfoPath.1;.NET CLR 2.0.50727)。
单击此处立即获得 .NET Framework 3.0。
此计算机的 userAgent 字符串为:Mozilla/4.0(可兼容;MSIE 6.0;
Windows NT 5.1;SV1;.NET CLR 1.1.4322;InfoPath.1;.NET CLR 2.0.50727)。
4、CheckBox控制Panel的显示和隐藏
function
changeDisabled(id, controlId)
{
$get(controlId).disabled = $get(id).checked ? '' : 'disabled';
}
{
$get(controlId).disabled = $get(id).checked ? '' : 'disabled';
}
CheckBoxArea.Attributes.Add(
"
onclick
"
, String.Format(
"
changeDisabled('{0}','{1}')
"
, CheckBoxArea.ClientID, AllProvincePanel.ClientID));
5、Asp.Net 2.0 TreeView的Checkbox级联操作
function
OnTreeNodeChecked()
{
//同时兼容ie和ff的写法,取事件对象
var evt = arguments[0] || window.event;// ie 和 ff下,都显示 "[object]"
var element = evt.srcElement || evt.target;////在 ie和ff下 取得 btn3对象
if(element.type == 'checkbox')
{
var childrenDivID = element.id.replace('CheckBox','Nodes');
var div = document.getElementById(childrenDivID);
if(div == null)return;
var checkBoxs = div.getElementsByTagName('INPUT');
for(var i=0; i < checkBoxs.length; i++)
{
if(checkBoxs[i].type == 'checkbox')
checkBoxs[i].checked = element.checked;
}
}
}
{
//同时兼容ie和ff的写法,取事件对象
var evt = arguments[0] || window.event;// ie 和 ff下,都显示 "[object]"
var element = evt.srcElement || evt.target;////在 ie和ff下 取得 btn3对象
if(element.type == 'checkbox')
{
var childrenDivID = element.id.replace('CheckBox','Nodes');
var div = document.getElementById(childrenDivID);
if(div == null)return;
var checkBoxs = div.getElementsByTagName('INPUT');
for(var i=0; i < checkBoxs.length; i++)
{
if(checkBoxs[i].type == 'checkbox')
checkBoxs[i].checked = element.checked;
}
}
}
treeForum.Attributes.Add(
"
OnClick
"
,
"
OnTreeNodeChecked(event)
"
);
http://itrust.cnblogs.com/archive/2006/04/03/365439.html