JS(javascript)操作数据库
//把数据写入数据库
function
res(){
//获取输入值(myname和mymail是两个文本框的id)
var
uname = document.getElementById("myname"
).value;
var
umail = document.getElementById("mymail"
).value;
//数据库连接对象
var
con = new
ActiveXObject("ADODB.Connection"
);
//连接字符串
var
str = "DRIVER={SQL SERVER}
;SERVER=(local);uid=sa;pwd=123456;database=xslt"
;
//打开数据源
con.Open(str);
//sql语句
var
sql = "insert into xslt(name,mail) values('"
+ uname + "','"
+ umail + "')"
;
try
{
//执行sql语句
con.Execute(sql);
//关闭连接
con.Close();
//转向成功页面
window.location.href = "http://www.aspxcs.net/";
}
catch
(e){
alert(e);
}
相关文档:
var myDate = new Date();
myDate.getYear(); //获取当前年份(2位)
myDate.getFullYear(); //获取完整的年份(4位,1970-????)
myDate.getMonth(); //获取当前月份(0-11,0代表1月)
myDate.getDate();   ......
Javascript刷新页面的几种方法:
1 history.go(0)
2 location.reload()
3 location=location
4 location.assign(location)
5 document.execCommand('Refresh')
6 window.navigate(location)
7& ......
JS自带函数
concat
将两个或多个字符的文本组合起来,返回一个新的字符串。
var a = "hello";
var b = ",world";
var c = a.concat(b);
alert(c);
//c = "hello,world"
indexOf
返回字符串中一个子串第一处出现的索引(从左到右搜索)。如果没有匹配项,返回 -1 。
var index1 = a.indexOf("l");
//index1 = 2 ......
语法
oNewWindow = window.open( [sURL] [, sName] [, sFeatures] )
sURL 可选. URL 字符串 . 如果URL为空, 将以about:blank打开.
sName 可选. 字符串 描述打开窗口的名字(name). 可以做为form 和 a 标签的TARGET属性值 .
sFeatures 可选. 字符串 格式如"fullscreen=yes,toolbar=yes".channelmode = { yes | no | ......
文件内容如下:(两个文件glossy.js和glossy.html)
/********************************** glossy.js ***********************************/
/**
* glossy.js 1.31 (19-Jul-2007)
* (c) by Christian Effenberger
* All Rights Reserved
* Source: glossy.netzgesta.de
* Distrib ......