html页面中同时使用
今天遇到个问题,想在页面中做个web sql存储,可是就是没反应,求各位大神帮我看看是哪的问题
具体代码是这样的
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Register</title>
<style type="text/css">
body{
font-family:arial;/*设置字体,font-family是字体的意思,Arial是一种通用的英文字体。*/
background-color:rgb(200,200,200);
}
h1{
text-shadow:5px 5px 5px gray; /*为文字添加阴影效果*/
color:rgb(255,255,255);/*设置文字颜色为白色*/
}
</style>
<script type="text/javascript">
var DB;
//创建数据库方法
function initDatabase(){
if(!window.openDatabase){
alert('浏览器不支持Web SQL数据库。');
}else{
var dbName='ydhdb';//定义数据库名称
var db.Version='1.0';//定义数据库版本
var dbDoc='DEMO Database';//定义数据库说明信息
var dbSize='10000';//定义数据库大小
DB = openDatabase(daName,dbVersion,dbDoc,dbSize);//创建数据表
}
}
//创建数据表
function createTable()
{
DB.transaction(function (tx){
tx.executesql('create table if not exists USERINFO(USERNAME,PASSWORD,)');
});
}
//注册方法
function register(){
initDatabase();
createTable();
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var sex = document.getElementById("sex").value;
var phone = document.getElementById("phone").value;
var specialty = document.getElementById("specialty").value;
var level = document.getElementById("level").value;
DB.transaction(function(tx){
tx.executeSql(
'select * from USERINFO where USERNAME=?',[username],
function(tx,rs){
if(rs.rows.length>0){ //用户名已存在
alert("该用户名已存在,请使用其他用户名注册。");
}
else{
DB.transaction(function(tx){
tx.executeSql{ //将新用户信息插入数据库
'insert into USERINFO(USERNAME,PASSWORD,SEX,PHONE,SPECIALTY,LEVEL) values(?,?,?,?,?,?)',
[username,password,sex,phone,specialty,level],
function(tx,rs){
alert('注册成功!');
},
function(tx,error){
alert('注册失败!');
}
};
})
}
}
);
});
}
</script>
</head>
<body>
<form method="post"align="center">
<h1>Register</h1>
<hr/>
<label for="Username">用户名:
<input type="text" name="Username" required="required" size="15" maxlength="30" checked="checked"/><br /></label>
<br/>
<label for="Password">密码:
<input type="password" name="password" required="required" size="15" maxlength="30"checked="checked"/><br/></label>
<br/>
<label for="Password">确认密码:
<input type="password" name="password" required="required" size="15" maxlength="30"checked="checked"/><br/></label>
<br/>
<label for="sex">性别:
<input type="radio" name="sex" value="男" checked="checked" />男
<input type="radio" name="sex" value="女" />女
<br/><br/></label>
<label for="phone ">手机号码:
<input type="text " name="phone" size="15" maxlength="30"/><br/></label>
<br/>
<label for="Specialty">专业:
<input type="text " name="specialty" size="15" maxlength="100"/><br/></label>
<br/>
<label for="level">
<input type="radio" name="level" value="audience" checked="checked"/>观众
<input type="radio" name="level" value="sportsman" />运动员
<br/><br/></label>
<input type="button" value="注册" onclick="register()" />
<input type="button" value="重新登录" onclick="javascript:window.location.href='login.html'">
</form>
</body>
</html>