|
.cs file
private void Page_Load (object sender, System.EventArgs e)
{
btnLogin.Attributes.Add ("onclick", "checkUserName ();");
}
html code:
<script language = "javascript" src = "ScriptFiles / BBS_JScript.js"> </ script>
Code in BBS_JScript.js:
function checkUserName ()
{
var isRight;
var userName = document.all ("txtUserName"). value;
var userNameLen = userName.length;
if (userName == "")
{
alert ("The username cannot be empty!");
isRight = false;
}
else
{
if (userNameLen> 6&&userNameLen <= 16)
{
isRight = true;
}
else
{
alert ("The username is between 6 and 16 characters long!");
isRight = false;
}
}
return isRight;
}
"Runtime error" and "Syntax error" occur when the page loads.
I put
else
{
alert ("The username is between 6 and 16 characters long!");
isRight = false;
}
There will be no problem if you delete it, I really do n’t understand why, please master, thank you |
|