2007年7月小记

1、WebMethod的浏览器客户端缓存
None.gif [WebMethod]
None.gif[ScriptMethod(UseHttpGet 
=   true )]
None.gif
public  DateTime GetServerTime()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    HttpCachePolicy cache 
= HttpContext.Current.Response.Cache;
InBlock.gif    cache.SetCacheability(HttpCacheability.Private);
InBlock.gif    cache.SetExpires(DateTime.Now.AddSeconds((
double)10));
InBlock.gif    
InBlock.gif    FieldInfo maxAgeField 
= cache.GetType().GetField(
InBlock.gif        
"_maxAge", BindingFlags.Instance |
 BindingFlags.NonPublic);
InBlock.gif    maxAgeField.SetValue(cache, 
new TimeSpan(0010
));
InBlock.gif    
InBlock.gif    
return DateTime.Now;
ExpandedBlockEnd.gif}
粗体部分可以修改Response中Header的设置Cache-Control    public, max-age=10
引用: http://www.cnblogs.com/JeffreyZhao/archive/2007/07/02/client_side_caching_for_script_method_access.html

2、在表格中插入一个行
None.gif < html  xmlns ="http://www.w3.org/1999/xhtml"   >
None.gif
< head  runat ="server" >
None.gif    
< title > 无标题页 </ title >
ExpandedBlockStart.gifContractedBlock.gif    
< script  language ="javascript"  type ="text/javascript" > dot.gif
InBlock.gif    
InBlock.gif        
function insertRow()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
var number = Math.floor(Math.random()*10+1);//1~10随机数
InBlock.gif

InBlock.gif            
var t = document.getElementById('myTable');
InBlock.gif            
var newRow = t.insertRow(-1);//表示在最后一行插入新行
InBlock.gif
            
InBlock.gif            
var newCell1 = newRow.insertCell();
InBlock.gif            newCell1.height 
= "20px";
InBlock.gif            newCell1.innerHTML 
= "<input type='text' id='test" + number +"' />";
InBlock.gif            
InBlock.gif            
var newCell2 = newRow.insertCell();
InBlock.gif            newCell2.height 
= "20px";
InBlock.gif            newCell2.innerHTML 
= "<input type='button' value='添加新行' οnclick='insertRow()' id='btn" + number + "' />";
InBlock.gif            
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    
</ script >
None.gif
</ head >
None.gif
< body >
None.gif    
< form  id ="form1"  runat ="server" >
None.gif    
< div >
None.gif        
< table  id ="myTable" >
None.gif            
< tr >
None.gif                
< td >
None.gif                    
< input  type ="text"   />
None.gif                
</ td >
None.gif                
< td >
None.gif                    
< input  type ="button"  value ="添加新行"  onclick ="insertRow()"   />
None.gif                
</ td >
None.gif            
</ tr >
None.gif        
</ table >
None.gif    
</ div >
None.gif    
</ form >
None.gif
</ body >
None.gif
</ html >
None.gif

3、附录 B:使用 Internet Explorer 检测 .NET Framework 3.0 的示例脚本
下实例显示了在浏览器中运行的 JavaScript 程序如何检测 .NET Framework 3.0 是否正在运行。该脚本将搜索用户代理字符串,并基于搜索结果显示状态消息。
None.gif <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
None.gif
< html  xmlns ="http://www.w3.org/1999/xhtml" >
None.gif
< head >
None.gif
< title > Test for NET Framework 3.0 </ title >
None.gif
< meta  http-equiv ="Content-Type"  content ="text/html; charset=utf-8" />
ExpandedBlockStart.gifContractedBlock.gif
< script  type ="text/javascript"  language ="JavaScript" > dot.gif
InBlock.gif    
<!--
InBlock.gif
var RequiredFXVersion = "3.0.04131.06";
InBlock.gif    
InBlock.gif
function window::onload()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif
var foundVer = CheckRequiredFXVersion(RequiredFXVersion);
InBlock.gif
if (foundVer != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gifresult.innerHTML 
= "此计算机有正确版本的 .NET Framework:" + foundVer + "."+ "<br/>"
InBlock.gif
+ "此计算机的 userAgent 字符串为:" + navigator.userAgent + "";
ExpandedSubBlockEnd.gif      }
 
InBlock.gif
else
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gifresult.innerHTML 
= "此计算机没有正确版本的 
InBlock.gif .NET Framework。<br/>
"
InBlock.gif
+ "<a href='http://msdn.microsoft.com/windowsvista/default.aspx'>单击此处</a> "
InBlock.gif
+ "立即获得 .NET Framework 3.0。<br>"
InBlock.gif
+ "此计算机的 userAgent 字符串为:" + navigator.userAgent + "";
ExpandedSubBlockEnd.gif      }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
//
InBlock.gif//
从用户代理字符串中检索可用版本
InBlock.gif//
并检查它们是否与所需版本相匹配。
InBlock.gif
    //
InBlock.gif
function CheckRequiredFXVersion(requiredVersion)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif
var userAgentString = navigator.userAgent.match(/\.NET CLR[ .][0-9.]+/g);
InBlock.gif
if (userAgentString != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif
var i;
InBlock.gif
for (i = 0; i < userAgentString.length; ++i)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
var ver = userAgentString[i].slice(9);
InBlock.gif
if (CheckVersion(requiredVersion, ver))
InBlock.gif
return ver;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif      }

InBlock.gif
return null;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
//
InBlock.gif//
检查某个特定版本是否为所需版本。
InBlock.gif
    //
InBlock.gif
function CheckVersion(requiredVersion, ver)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gifrequiredVersion 
= requiredVersion.split(".");
InBlock.gifver 
= ver.split(".");
InBlock.gif      
InBlock.gif
//主要版本号必须严格匹配。
InBlock.gif
if (requiredVersion[0!= ver[0])
InBlock.gif
return false;
InBlock.gif      
InBlock.gif
//次要版本号/版号必须不低于所需版本。
InBlock.gif
var i;
InBlock.gif
for (i = 1; i < requiredVersion.length && i < ver.length; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif
if (new Number(ver[i]) < new Number(requiredVersion[i]))
InBlock.gif
return false;
ExpandedSubBlockEnd.gif      }

InBlock.gif
return true;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
ExpandedBlockEnd.gif    
-->
None.gif
</ script >
None.gif
</ head >
None.gif
< body >
None.gif
< div  id ="result"   />
None.gif
</ body >
None.gif
</ html >
None.gif
None.gif

如果成功搜索到字符串“.NET Framework 3.0”,将显示以下消息:
None.gif 此计算机有正确版本的 .NET Framework:3.0.04131.06。
None.gif
None.gif此计算机的 userAgent 字符串为:Mozilla/4.0(可兼容;MSIE 6.0;
None.gifWindows NT 5.1;SV1;.NET CLR 1.1.4322;.NET CLR 2.0.50727;.NET CLR 3.0.04131.06)。

否则,会显示以下消息:
None.gif 此计算机没有正确版本的 .NET Framework。
None.gif
None.gif单击此处立即获得 .NET Framework 3.0。
None.gif
None.gif此计算机的 userAgent 字符串为:Mozilla/4.0(可兼容;MSIE 6.0;
None.gifWindows NT 5.1;SV1;.NET CLR 1.1.4322;InfoPath.1;.NET CLR 2.0.50727)。

4、CheckBox控制Panel的显示和隐藏
None.gif      function  changeDisabled(id, controlId)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        $get(controlId).disabled 
= $get(id).checked ? '' : 'disabled';
ExpandedBlockEnd.gif    }

None.gif CheckBoxArea.Attributes.Add( " onclick " , String.Format( " changeDisabled('{0}','{1}') " , CheckBoxArea.ClientID, AllProvincePanel.ClientID));

5、Asp.Net 2.0 TreeView的Checkbox级联操作
None.gif      function  OnTreeNodeChecked() 
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif         
//同时兼容ie和ff的写法,取事件对象 
InBlock.gif        
var evt = arguments[0|| window.event;// ie 和 ff下,都显示 "[object]"
InBlock.gif
        var element = evt.srcElement || evt.target;////在 ie和ff下  取得 btn3对象
InBlock.gif
        
InBlock.gif        
if(element.type == 'checkbox')
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
var childrenDivID = element.id.replace('CheckBox','Nodes');
InBlock.gif            
var div = document.getElementById(childrenDivID); 
InBlock.gif            
if(div == null)return;
InBlock.gif            
var checkBoxs = div.getElementsByTagName('INPUT');
InBlock.gif            
for(var i=0; i < checkBoxs.length; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(checkBoxs[i].type == 'checkbox') 
InBlock.gif                    checkBoxs[i].checked 
= element.checked;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }


None.gif treeForum.Attributes.Add( " OnClick " " OnTreeNodeChecked(event) " );

http://itrust.cnblogs.com/archive/2006/04/03/365439.html



转载于:https://www.cnblogs.com/BillChen/archive/2007/07/03/803897.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值