问题:外部JavaScript无效。
我希望我的注册页面得到验证,我已经编写了代码,但我不知道在哪里调用它我尝试了以下内容。
这是我的javascript代码:
let companiesTable = db["companies"] // get the table from our SQLite Database
db.transaction(.Deferred) { txn in
for (index,company) in data {
if companiesTable.insert(name <- company["name"]!), shortname <- company["short_name"]).statement.failed {
return .Rollback
}
}
return .Commit
}
我试过这样:
var emailRegex = /^[A-Za-z0-9._]*\@[A-Za-z]*\.[A-Za-z]{2,5}$/;
var fname = document.form.Name.Value;
var lname = document.form.Last.value;
var fpassword = document.form.password.value;
var frassword = document.form.repassword.value;
var femail = document.form.Email.value;
function submit()
{
if ( fname === "")
{
document.form.Name.focus();
alert("Please enter the name");
return false;
}
if ( lname === "")
{
document.form.Last.focus();
alert("Please enter last name");
return false;
}
if( fpassword === "")
{
document.form.password.focus();
alert("You can't leave password empty");
return false;
}
if( frassword === "")
{
document.form.repassword.focus();
alert("Please confirm password");
return false;
}
if( femail === "")
{
document.form.Email.focus();
alert("Don't leave Email blank");
return false;
}
else if (!emailRegex.test(femail))
{
document.form.Email.focus();
alert("Not a valid Email");
return false;
}
if( fname !== '' && lname !== '' && fpassword !== '' && frassword !== '' && femail !== '')
{
alert("Registration sucessfull");
}
}
我也尝试了这个:
<script type="text/javascript" src="skill.js"></script>
<script>
submit();
</script>
答案 0 :(得分:0)
在submit
元素中创建button
form
,如下所示 -
<input type="submit" value="Submit" />
然后在开始attribute
标记上添加form
,就像这样 -
<form name="form" onsubmit="submit()">
确保您已经链接到您的JS文件。