2011年8月23日

JavaScript 在页面加载过程中执行的顺序

看这样一个例子:

<!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>Hello World jQuery!</title>
     <script type="text/javascript" >
        alert("1,i can't control any html element");
    </script>
</head>
<body>
    <div id="divMsg">展示javascript在页面不同位置执行的顺序</div>
    <input id="btnShow" type="button" value="2,i can control this element" />
    <br />
    <img src="http://img.mm-girl.com/photo/209/chenqiaoen-459209.jpg">
    <script type="text/javascript" >
        alert(document.getElementById("btnShow").value); 
        window.onload=last;
        function last()
        {alert("3,i will be executed after the loading of all the pictures ");}
    </script>
</body>
</html>

第一个javascript函数是在任何dom结构都未加载时候执行的,第二个javascript函数是在dom结构加载完成时候执行的,此时图片等还未加载完成,第三个javascript函数是在所有图片都加载完成时候执行的。

posted @ 2011-08-23 10:58 catvi 阅读(42) 评论(0) 编辑

2011年5月27日

一组sharepoint中组合各种功能的JavaScript

介绍下大概的功能:

raddio button 列变行的功能;

载入页面时候改变source的链接,这样就可以改变OKbutton的走向;

加入自定义按钮,根据页面选项,动态决定点击按钮之后页面,同时更新页面内容;

利用form action 按钮的提交功能更新页面,利用setTimeout在更新页面内容后异步导向新的页面链接。

<script type='text/javascript'>
  function AdjustTable(objTab)
{
  var tabArray = new Array();
  for(var i = 0;i<objTab.rows[0].cells.length;i++)
  {
   var tmpArray = new Array()
 for(var j = 0; j<objTab.rows.length;j++)
 {
  tmpArray[tmpArray.length] = objTab.rows[j].cells[i].outerHTML
 }
 tabArray[tabArray.length] = tmpArray;
  }
  var str = "";
 
  for(var i =0;i<tabArray.length;i++)
  {
   str += "<tr>" + tabArray[i].join("") + "</tr>"
  }
  str = "<table  id=\"tab\">" + str + "</table>";
 objTab.outerHTML = str
}
function Adjust()
{
var table1=document.getElementById("ctl00_m_g_e80015a3_8d3b_4fd2_abab_cce5971c2a8d_ff1_1_ctl00_ctl00").parentNode.parentNode.parentNode.parentNode.parentNode;
AdjustTable(table1);
var table2=document.getElementById("ctl00_m_g_e80015a3_8d3b_4fd2_abab_cce5971c2a8d_ff2_1_ctl00_ctl00").parentNode.parentNode.parentNode.parentNode.parentNode;
AdjustTable(table2);
var table3=document.getElementById("ctl00_m_g_e80015a3_8d3b_4fd2_abab_cce5971c2a8d_ff3_1_ctl00_ctl00").parentNode.parentNode.parentNode.parentNode.parentNode;
AdjustTable(table3);
var table4=document.getElementById("ctl00_m_g_e80015a3_8d3b_4fd2_abab_cce5971c2a8d_ff4_1_ctl00_ctl00").parentNode.parentNode.parentNode.parentNode.parentNode;
AdjustTable(table4);
var table5=document.getElementById("ctl00_m_g_e80015a3_8d3b_4fd2_abab_cce5971c2a8d_ff5_1_ctl00_ctl00").parentNode.parentNode.parentNode.parentNode.parentNode;
AdjustTable(table5);
var table6=document.getElementById("ctl00_m_g_e80015a3_8d3b_4fd2_abab_cce5971c2a8d_ff6_1_ctl00_ctl00").parentNode.parentNode.parentNode.parentNode.parentNode;
AdjustTable(table6);
var table7=document.getElementById("ctl00_m_g_e80015a3_8d3b_4fd2_abab_cce5971c2a8d_ff7_1_ctl00_ctl00").parentNode.parentNode.parentNode.parentNode.parentNode;
AdjustTable(table7);
var table8=document.getElementById("ctl00_m_g_e80015a3_8d3b_4fd2_abab_cce5971c2a8d_ff8_1_ctl00_ctl00").parentNode.parentNode.parentNode.parentNode.parentNode;
AdjustTable(table8);
var table9=document.getElementById("ctl00_m_g_e80015a3_8d3b_4fd2_abab_cce5971c2a8d_ff9_1_ctl00_ctl00").parentNode.parentNode.parentNode.parentNode.parentNode;
AdjustTable(table9);
var table10=document.getElementById("ctl00_m_g_e80015a3_8d3b_4fd2_abab_cce5971c2a8d_ff10_1_ctl00_ctl00").parentNode.parentNode.parentNode.parentNode.parentNode;
AdjustTable(table10);

var table0=document.getElementById("ctl00_m_g_e80015a3_8d3b_4fd2_abab_cce5971c2a8d_ff34_1_ctl00_ctl00").parentNode.parentNode.parentNode.parentNode.parentNode;
AdjustTable(table0);

}
_spBodyOnLoadFunctionNames.push("Adjust");


 function GetQueryString(name)     
{     
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");     
     var r = window.location.search.substr(1).match(reg);     
     if (r!=null)
     {
      return unescape(r[2]);
     }
     else
     {
      return "";
     } 
}

function JudgePrevious()
{

 var ID=GetQueryString('ID');
 var lowrisk=document.getElementById("ctl00_m_g_e80015a3_8d3b_4fd2_abab_cce5971c2a8d_ff17_1_ctl00_ctl00_TextField");
 var strUrl=window.location.href;
 var url=strUrl.substring(0,strUrl.lastIndexOf('/'));
   
 var btnHiddenSave=document.getElementById("btnHiddenSave");
 if(lowrisk.value=='1')
 {
    setTimeout("ChangeURL('EditRiskAssessment2.aspx')", 500);
    btnHiddenSave.click();
 }
 else
 {
    setTimeout("ChangeURL('EditRiskAssessmentDispensation.aspx')", 500);
    btnHiddenSave.click();
 }
 
}


function PreSaveAction()
{
     var ID=GetQueryString('ID');
     var lowrisk = document.getElementById('ctl00_m_g_e80015a3_8d3b_4fd2_abab_cce5971c2a8d_ff17_1_ctl00_ctl00_TextField');  

     if(lowrisk.value=='0')
     {
       return true;
     }   
    setTimeout("ChangeURL('EditProtectControlLR.aspx')", 500);
   
    var btnHiddenSave=document.getElementById("btnHiddenSave");
    btnHiddenSave.click();
}

function ChangeURL(url)
{
var ID=GetQueryString('ID');
window.location.href=url+'?ID='+ID;
}
function SetFields()
{
    var ID=GetQueryString('ID');
    if(window.location.href.indexOf('Source')<=0)
    {
      var strUrl=window.location.href;
      var url=strUrl.substring(0,strUrl.lastIndexOf('/'));  
      window.location.href=window.location+"&Source="+url+"/EditProtectControlNLR.aspx?ID="+ID;
    }   
}
 

SetFields();
</script>

posted @ 2011-05-27 10:54 catvi 阅读(186) 评论(0) 编辑

JavaScript 调用sharepoint内置webservice(UpdateListItems和GetListItem())

///////UpdateListItems

function UpdateListItem()
 {

  var listName="End User Computing List";
  var a = new ActiveXObject("Microsoft.XMLHTTP");
  if(a == null) return 'error';
 
  var ID=GetQueryString('ID');
  var ddlEvaluation = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff15_1_ctl00_DropDownChoice');
    
     var ddl1 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff17_1_ctl00_DropDownChoice');
     var ddl2 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff18_1_ctl00_DropDownChoice');
     var ddl3 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff19_1_ctl00_DropDownChoice');
     var ddl4 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff20_1_ctl00_DropDownChoice');
     var ddl5 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff21_1_ctl00_DropDownChoice');
     var ddl6 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff22_1_ctl00_DropDownChoice'); 
    
     var ddlTechType = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff16_1_ctl00_DropDownChoice');
     var txtTechType = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff23_1_ctl00_ctl00_TextField');

      
  a.Open("POST","http://cntsnapp102.zone1.scb.net:2020/_vti_bin/lists.asmx", false);
  a.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
  a.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
  var d = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
        + '<soap:Body>'
        + '<UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">'
        + '<listName>' + listName + '</listName>'
        + '<updates><Batch OnError="Continue" ListVersion="1">'
        + '<Method ID="1" Cmd="Update">'
        + '<Field Name="ID">' + ID+ '</Field>'
        + '<Field Name="Criticality_x0020_Evaluation">' + ddlEvaluation.value+ '</Field>'
        + '<Field Name="Biz_x0020_Use">' + ddl1.value+ '</Field>'
        + '<Field Name="Biz_x0020_Use2">' + ddl2.value+ '</Field>'
        + '<Field Name="Biz_x0020_Use3">' + ddl3.value+ '</Field>'
        + '<Field Name="Biz_x0020_Use4">' + ddl4.value+ '</Field>'
        + '<Field Name="Biz_x0020_Use5">' + ddl5.value+ '</Field>'
        + '<Field Name="Biz_x0020_Use6">' + ddl6.value+ '</Field>'
        + '<Field Name="Tech_x0020_Type">' + ddlTechType.value+ '</Field>'
        + '<Field Name="Tech_x0020_Type_x0020_Text">' + txtTechType.value+ '</Field>'
        + '</Method>'
        + '</Batch></updates>'
        + '</UpdateListItems>'
        + '</soap:Body>'
        + '</soap:Envelope>';
   a.Send(d);
 }

//////GetListItems:

function GetListItem()
{

  var listName="End User Computing List";
  var a = new ActiveXObject("Microsoft.XMLHTTP");
  if(a == null) return 'error';
 
  var id=GetQueryString('ID');
  var query = '<Query><Where><Eq><FieldRef Name="ID"/><Value Type="Counter">'+id+ '</Value></Eq></Where></Query>';
  var view = '<ViewFields><FieldRef Name="Low_x0020_Risk"/><FieldRef Name="Business_x0020_Case_x0020_input"/><FieldRef Name="Procedure_x0020_reading"/><FieldRef Name="Risk_x0020_assessment"/><FieldRef Name="Documentation"/><FieldRef Name="Sign_x002d_off"/><FieldRef Name="Closure"/></ViewFields>';

  a.Open("POST","http://cnt5445.zone1.scb.net:2000000/_vti_bin/lists.asmx", false);
  a.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
  a.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListItems");
  var d = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
        + '<soap:Body>'
        + '<GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">'
        + '<listName>' + listName + '</listName>'
        + '<query>'+query+'</query>'
        + '<viewFields>'+view+'</viewFields>'
        + '<rowLimit>1</rowLimit>'       
        + '</GetListItems>'
        + '</soap:Body>'
        + '</soap:Envelope>';
   a.Send(d);
   if(a.status==200)
   {
  
    var rows=a.responseXML.getElementsByTagName('z:row');
    if(rows.length == 1)
    {
     lowRisk=rows[0].getAttribute('ows_Low_x0020_Risk');
     process1=rows[0].getAttribute('ows_Business_x0020_Case_x0020_input');
     process2=rows[0].getAttribute('ows_Procedure_x0020_reading');
     process3=rows[0].getAttribute('ows_Risk_x0020_assessment');
     process4=rows[0].getAttribute('ows_Documentation');
     process5=rows[0].getAttribute('ows_Sign_x002d_off');
     process6=rows[0].getAttribute('ows_Closure');

     //alert('title:' + lowRisk);
     var href4=document.getElementById('href4');
     var href5=document.getElementById('href5');
     var href6=document.getElementById('href6');

     if(lowRisk=='1')
     {
      href5.href='EditControlsLR.aspx?ID='+id;
      href4.href='EditRiskAssessmentVender.aspx?ID='+id;
      href6.href='EditDocumentationManagement.aspx?ID='+id;
     }
     if(lowRisk=='0')
     {
      href5.href='EditControlsNLR.aspx?ID='+id;
       href4.href='EditRiskAssessmentVender.aspx?ID='+id;
      href6.href='EditDocumentationManagement.aspx?ID='+id;
     }
    
     var img1=document.getElementById('img1');
     if(process1=='1'){img1.src='http://images.cnblogs.com/green.png';}
     else{img1.src='http://images.cnblogs.com/red.png';}
      var img2=document.getElementById('img2');
     if(process2=='1'){img2.src='http://images.cnblogs.com/green.png';}
     else{img2.src='http://images.cnblogs.com/red.png';}
      var img3=document.getElementById('img3');
     if(process3=='1'){img3.src='http://images.cnblogs.com/green.png';}
     else{img3.src='http://images.cnblogs.com/red.png';}
      var img4=document.getElementById('img4');
     if(process4=='1'){img4.src='http://images.cnblogs.com/green.png';}
     else{img4.src='http://images.cnblogs.com/red.png';}
      var img5=document.getElementById('img5');
     if(process5=='1'){img5.src='http://images.cnblogs.com/green.png';}
     else{img5.src='http://images.cnblogs.com/red.png';}
      var img6=document.getElementById('img6');
     if(process6=='1'){img6.src='http://images.cnblogs.com/green.png';}
     else{img6.src='http://images.cnblogs.com/red.png';}

    }
   }
}

posted @ 2011-05-27 10:47 catvi 阅读(74) 评论(0) 编辑

2011年3月31日

域中搜索用户email

    static public string GetEmailByUserID(string user_id, string pwd, string neededUser_ID)
        {
            string email = "";
            DirectoryEntry entry = new DirectoryEntry("LDAP://zone1.scb.net", user_id, pwd);
            DirectorySearcher searcher = new DirectorySearcher(entry);
            searcher.Filter = "(SAMAccountName=" + neededUser_ID + ")";
            searcher.PropertiesToLoad.Add("SAMAccountName");
            searcher.PropertiesToLoad.Add("mail");
            SearchResult result = searcher.FindOne();
            if (result != null)
            {
                if (result.Properties.Contains("mail"))
                {
                    email = (string)result.Properties["mail"][0];
                }
            }
            if (entry != null)
            {
                entry.Dispose();
            }
            return email;
        }

posted @ 2011-03-31 15:08 catvi 阅读(25) 评论(0) 编辑

2011年3月10日

JavaScript 函数在浏览器中直接调用的方法

直接在浏览器栏输入:javascript:Get(); 后面是函数的名称,就可以调用了啊。

当然前提是这个函数Get()在此页面中存在。

posted @ 2011-03-10 13:03 catvi 阅读(30) 评论(0) 编辑

2011年3月9日

转:SQL重复记录查询

select distinct *  into #Temp from RepeatAll
drop table RepeatAll
select * into RepeatAll from #Temp
drop table #Temp

select identity(int,1,1) id,* into #Temp from RepeatAll
drop table RepeatAll
--select
select name,sex,address from #Temp group by name,sex,address having (count(*)>1)
--delete
delete from #Temp where id not in
(select min(id) id from #Temp group by name,sex,address)
select name,sex,address into RepeatAll from #Temp
drop table #Temp

posted @ 2011-03-09 10:55 catvi 阅读(13) 评论(0) 编辑

转:SQl大数据量操作效率以及日志测试

/*--SQL   Server   中的最小日志记录操作

原作: happydreamer(小黑)

--整理..邹建--2003.12--*/


/*--控制数据库恢复选项

ALTER   DATABASE   数据库名   SET   RECOVERY   <RECOVERY_OPTIONS>

<RECOVERY_OPTIONS> 的取值:   FULL   |   BULK_LOGGED   |   SIMPLE  

FULL: 系统将对介质错误提供完全保护。
如果数据文件损坏,介质恢复可以还原所有已提交的事务。  

BULK_LOGGED: 将在介质错误保护程度与某些大规模或大容量操作
的最优性能及日志存储空间最少占用量之间进行权衡。
这些操作包括:
SELECT   INTO、
大容量装载操作(bcp   和   BULK   INSERT)、CREATE   INDEX
文本和图象操作(WRITETEXT   和   UPDATETEXT)。

在大容量日志记录恢复模型下,对整个类只做最少的日志记录,
并且无法逐个操作地控制日志记录行为。

SIMPLE: 系统将提供占用日志空间最小的备份策略。
服务器故障恢复不再需要的日志空间可被自动重用。

重要     简单恢复模型比其它两种模型更容易管理,
但数据文件损坏时造成数据丢失的可能性更大。
最近的数据库备份或差异数据库备份之后的更改都将丢失,必须手工重新输入。

默认恢复模型由   model   数据库的恢复模型确定。
若要更改新数据库的默认值,请用   ALTER   DATABASE   设置   model   数据库的恢复选项。
--*/

/*--
三种恢复模型对这些操作记录日志情况比较

使用了一个未公开的函数:   fn_dblog
可以看日志文件的记录数
用法:select   count(*)   from   ::fn_dblog(null,null)  
--*/

--1.简单恢复模型

--创建测试数据库
use   master
go

create   database   test
go

--打开创建的测试数据库
use   test
go

--设置恢复模型为:简单模型
alter   database   test   set   recovery   simple

--插入数据测试
select   top   10000   a.*   into   testtable  
from   master..sysobjects   a   ,   master..syscolumns   b

--查看日志文件中的记录数
select   count(*)   from   ::fn_dblog(null,null)    

--事务日志空间使用情况
dbcc   sqlperf(logspace)
go

--删除测试的数据库
use   master
drop   database   test
go


--2.大容量日志记录恢复模型
/*--说明
    这些大容量复制操作的数据丢失程度要比完全恢复模型严重,
    不允许恢复部分的BULK操作,只能全部恢复
--*/

--创建测试数据库
use   master
go

create   database   test
go

--打开创建的测试数据库
use   test
go

--设置恢复模型为:大容量日志记录
alter   database   test   set   recovery   BULK_LOGGED  

--插入数据测试
select   top   10000   a.*   into   testtable   from   master..sysobjects   a   ,   master..syscolumns   b

--查看日志文件中的记录数
select   count(*)   from   ::fn_dblog(null,null)    

--事务日志空间使用情况
dbcc   sqlperf(logspace)
go

--删除测试的数据库
use   master
drop   database   test
go

--3.完全恢复模型
/*--说明
    记录的日志数要比大容量日志记录恢复模型多,
    将记录每一条BCP   or   BULK   insert,create   index   的每一条index   row,
    对image,text字段   WRITETEXT   or   UPDATETEXT的所有操作
--*/

--创建测试数据库
use   master
go

create   database   test
go

--打开创建的测试数据库
use   test
go

--设置恢复模型为:完全恢复模型
alter   database   test   set   recovery   full  

--插入数据测试
select   top   10000   a.*   into   testtable   from   master..sysobjects   a   ,   master..syscolumns   b

--查看日志文件中的记录数
select   count(*)   from   ::fn_dblog(null,null)    

--事务日志空间使用情况
dbcc   sqlperf(logspace)
go

--删除测试的数据库
use   master
drop   database   test
go

/*--我的电脑上测试结果

恢复模型 速度 日志记录数 日志的可用空间 日志信息占用的百分比(%)
---------------   -------   -----------   ---------------   ------------------------
简单模型 <=1秒 385 0.484375 46.673386
大容量日志记录 <=1秒 408 0.484375 47.177418
完全恢复模型 9秒 560 1.9921875 85.416664

--*/

/*--结论

恢复模型 速度 日志大小 安全性
---------------   -------   -----------   ---------
简单模型 快 很 低
大容量日志记录 快 小 较低
完全恢复模型 慢 大 高
--*/

posted @ 2011-03-09 10:52 catvi 阅读(153) 评论(0) 编辑

2011年2月28日

在SP中点击OK按钮可以自定义一个必须执行的脚步函数

摘要: function PreSaveItem() { var select = document.getElementById('ctl00_PlaceHolderMain_g_bd8d0ff5_0d1f_40ec_8057_d037295bcd8a_DropDownList1ID0EAAA'); var value = select.value; if (value == "Destroyed") { if(getField('textarea','DestroyedCause').value=='') { al阅读全文

posted @ 2011-02-28 14:02 catvi 阅读(21) 评论(2) 编辑

2011年2月24日

精通系列之Windows命令行

摘要: notepad打开记事本 msconfig.exe-系统配置实用程序 Regedit.exe注册表 Eventvwr-事件查看器 calc-启动计算器Dxdiag-检查DirectX信息dcomcnfg-打开系统组件服务 mspaint画图板阅读全文

posted @ 2011-02-24 15:01 catvi 阅读(12) 评论(0) 编辑

2011年2月23日

精通系列之Windows7

摘要: 快捷键之显示桌面:win+d或者是:win+m两者不同是,win+d显示桌面以后再按win+d回到显示桌面前的界面,win+m则不会阅读全文

posted @ 2011-02-23 20:30 catvi 阅读(12) 评论(0) 编辑