Cloning Nodes 节点克隆
Another way of updating page contents using DOM methods is to clone existing DOM elements instead of creating new ones—in other words, using element.cloneNode() (where element is an existing node) instead of document.createElement().
使用DOM方法更新页面内容的另一个途径是克隆已有DOM元素,而不是创建新的——即使用element.cloneNode()(element是一个已存在的节点)代替document.createElement();
Cloning nodes is more efficient in most browsers, but not by a big margin. Regenerating the table from the previous example by creating the repeating elements only once and then copying them results in slightly faster execution times:
在大多数浏览器上,克隆节点更有效率,但提高不太多。用克隆节点的办法重新生成前面例子中的表,单元只创建一次,然后重复执行复制操作,这样做只是稍微快了一点:
• 2% in IE8, but no change in IE6 and IE7
在IE8中快2%,但在IE6和IE7中无变化
• ......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>five-in-a-raw</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style>
<!--
table{text-align: center;font-size: 20px;cursor: hand;empty-cells: show;table-layout: fixed;}
-->
</style>
</head>
<script type="text/javascript">
<!--
function FiveRawGame(){
this.redChess="<font color=\"red\">X</font>";
this.blackChess="<font color='black'>O</font>";
//初始化棋盘和数据
this.init=function(){
var str="<table width=\"600\" height=\"600;\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" >";
for(var i=0;i<25;i++){
str+="<tr heig ......
C#代码与javaScript函数的相互调用
问:
1.如何在JavaScript访问C#函数?
2.如何在JavaScript访问C#变量?
3.如何在C#中访问JavaScript的已有变量?
4.如何在C#中访问JavaScript函数?
问题1答案如下:
javaScript函数中执行C#代码中的函数:
方法一:1、首先建立一个按钮,在后台将调用或处理的内容写入button_click中;
2、在前台写一个js函数,内容为document.getElementById("btn1").click();
3、在前台或后台调用js函数,激发click事件,等于访问后台c#函数;
方法二:1、函数声明为public
后台代码(把public改成protected也可以)
public string ss()
{
&nb ......
C#代码与javaScript函数的相互调用
问:
1.如何在JavaScript访问C#函数?
2.如何在JavaScript访问C#变量?
3.如何在C#中访问JavaScript的已有变量?
4.如何在C#中访问JavaScript函数?
问题1答案如下:
javaScript函数中执行C#代码中的函数:
方法一:1、首先建立一个按钮,在后台将调用或处理的内容写入button_click中;
2、在前台写一个js函数,内容为document.getElementById("btn1").click();
3、在前台或后台调用js函数,激发click事件,等于访问后台c#函数;
方法二:1、函数声明为public
后台代码(把public改成protected也可以)
public string ss()
{
&nb ......
function db()
{
//活动编号
var activeid = Request.Form("activeid");
//用户名
var username = Request.Form("username");
//手机号码
var mobile = Request.Form("mobile");
var conn= Server.CreateObject("ADODB.connection");
var rs= Server.CreateObject("adodb.recordset");
var userid = getUserIdByName(username);
conn.open("PROVIDER=SQLOLEDB;DATA SOURCE=127.0.0.1;UID=sa;PWD=123456;DATABASE=test");
var sql = "insert into user (activeid,userid,chrtel,dtappenddate) values("+activeid+","+userid+",'"+mobile+"',getdate())";
rs.open(sql,conn);
rs.close();
conn.close();
rs=null;
conn=null;
}
function getUserIdByName(username)
{
var conn= Server.CreateObject("ADODB.connection");
var rs= Server.CreateObject("adodb.recordset");
conn.open("PROVIDER=SQLOLEDB;DATA SOURCE=127.0.0.1;UID=sa;PWD=123456;DATABA ......
function db()
{
//活动编号
var activeid = Request.Form("activeid");
//用户名
var username = Request.Form("username");
//手机号码
var mobile = Request.Form("mobile");
var conn= Server.CreateObject("ADODB.connection");
var rs= Server.CreateObject("adodb.recordset");
var userid = getUserIdByName(username);
conn.open("PROVIDER=SQLOLEDB;DATA SOURCE=127.0.0.1;UID=sa;PWD=123456;DATABASE=test");
var sql = "insert into user (activeid,userid,chrtel,dtappenddate) values("+activeid+","+userid+",'"+mobile+"',getdate())";
rs.open(sql,conn);
rs.close();
conn.close();
rs=null;
conn=null;
}
function getUserIdByName(username)
{
var conn= Server.CreateObject("ADODB.connection");
var rs= Server.CreateObject("adodb.recordset");
conn.open("PROVIDER=SQLOLEDB;DATA SOURCE=127.0.0.1;UID=sa;PWD=123456;DATABA ......
<script>
//写cookies函数 作者:翟振凯
function
SetCookie(name,value)//两个参数,一个是cookie的名子,一个是值
{
var Days = 30;
//此 cookie 将被保存 30 天
var exp = new Date(); //new
Date("December 31, 9998");
exp.setTime(exp.getTime() +
Days*24*60*60*1000);
document.cookie = name + "="+ escape (value)
+ ";expires=" + exp.toGMTString();
}
function
getCookie(name)//取cookies函数
{
var arr =
document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return unescape(arr[2]); return null;
}
function
delCookie(name)//删除cookie
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null) document.cookie= name +
"="+cval ......
var
xmlDoc
=
null
;
function
parseXML
(
xmlUrl
)
{
try
{
//IE
xmlDoc
=
new
ActiveXObject
(
"Microsoft.XMLDOM"
);
xmlDoc
.
async
=
false
;
xmlDoc
.
load
(
xmlUrl
);
}
catch
(
e
)
{
try
{
//
Firefox
,
Mozilla
,
Opera
,
etc
.
xmlDoc
=
document
.
implementation
.
createDocument
(
""
,
""
,
null
);
xmlDoc
.
async
=
false
;
xmlDoc
.
load
(
xmlUrl
);
}
catch
(
e
)
{
try
{
//
google
,
Safari
var
xmlhttp
=
new
window
.
XMLHttpRequest
();
xmlhttp
.
open
(
"GET"
,
xmlUrl
,
false
);
xmlhttp
.
send
(
null
);
......
var
xmlDoc
=
null
;
function
parseXML
(
xmlUrl
)
{
try
{
//IE
xmlDoc
=
new
ActiveXObject
(
"Microsoft.XMLDOM"
);
xmlDoc
.
async
=
false
;
xmlDoc
.
load
(
xmlUrl
);
}
catch
(
e
)
{
try
{
//
Firefox
,
Mozilla
,
Opera
,
etc
.
xmlDoc
=
document
.
implementation
.
createDocument
(
""
,
""
,
null
);
xmlDoc
.
async
=
false
;
xmlDoc
.
load
(
xmlUrl
);
}
catch
(
e
)
{
try
{
//
google
,
Safari
var
xmlhttp
=
new
window
.
XMLHttpRequest
();
xmlhttp
.
open
(
"GET"
,
xmlUrl
,
false
);
xmlhttp
.
send
(
null
);
......