代码阅读总结(个人总结开发小技巧)

时间:2022-07-14 02:40:38


==阅读FMStocks7
1.利用js脚本控制2个文本框,
其中一个文本框中内容变化时自动清除另一个文本框中的内容

< input  type ="text"   onpropertychange ="c()"  id ="a" >  
< input  type ="text"   onpropertychange ="c()"  id ="b" >

 

< script language = " javascript " >
var  inHandler = false ;                                                                
function  c()
{
    
if (inHandler)
                    
return ;
                inHandler
= true ;
        
var  srcId  =  event.srcElement.id;                
                                
        
if ( srcId  ==   " a "  )
           {                   
           document.all.b.value 
=   "" ;                   
           }
        
else   if ( srcId  ==   " b "  )
           {                   
           document.all.a.value 
=   "" ;                   
           }
                inHandler
= false ;
        }
</ script >

我们必须要变量inHandler,要不然在事件onpropertychange发生后会陷入死循环

2.页面启动时,聚焦文本框tickerInputText,并选中里面的文本

< input  type ="text"  id ="tickerInputText"  maxlength ="6"   runat ="SERVER" >

< body  onload ="window_onload()" >

 

< script language = " javascript " >

     
function  window_onload() 
        {
        window_onload_runalways();

        
if  ( document.all.tickerInputText )
           {
           document.all.tickerInputText.select();
           document.all.tickerInputText.focus();
           }
        }

</ script >


 ===ASP.NET TimeTracker
1.判断是否为移动设备

public   static   bool  IsMobileDevice 
        {
            
get  
            {
                HttpContext context 
=  HttpContext.Current;
                
return  context.Request.Browser[ " IsMobileDevice " ==   " true "   ||  context.Request.Browser.Platform  ==   " WinCE " ;
            }
        }

2.表格字段排序属性的利用

string  SortField 
{
     
get  
     {
          
object  o  =  ViewState[ " SortField " ];
          
if  (o  ==   null
          {
               
return  String.Empty;
          }
          
return  ( string )o;
      }
      
set  
      {
           
if  (value  ==  SortField) 
           {   
               SortAscending 
=   ! SortAscending;
           }
           ViewState[
" SortField " =  value;
       }
}




bool  SortAscending 
{
     
get  
     {
          
object  o  =  ViewState[ " SortAscending " ];
          
if  (o  ==   null
          {
              
return   true ;
          }
          
return  ( bool )o;
      }
      
set  
      {
           ViewState[
" SortAscending " =  value;
      }
}


===其他
1.有时候你的页面只有一个固定的地方,但是需要显示非常多的数据,亦或是也不定,但是只有固定的一个地方给你显示它了。这时你就可以用下面这招,自动出滚动条,而且适用许多控件。很简单将你的控件放在一个DIV中将overflow属性设置成auto

< div  style ="height:400px;width:200px;overflow:auto" >

< div >