Copy codeThe Code is as follows:
<Script src = "jquery-1.9.1.js"> </script>
<Script type = "text/javascript">
$ ('# TxtUserName'). focus (function (){
$ ('# TxtUserName'). val ('');
})
$ ('# TxtPassWord'). focus (function (){
$ ('# TxtPassWord'). val ('');
})
$ ('# TxtUserName'). blur (function (){
If ($ ('# txtUserName'). val () = '')
{
$ ('# Txtusername'). val ('user name cannot be blank ');
// Obtain the focus again
// $ ('# TxtUserName'). focus ();
}
})
$ ('# TxtPassWord'). blur (function (){
If ($ ('# txtPassWord'). val () = ''){
$ ('# TxtPassWord'). val ('password cannot be blank ');
}
})
$ ('# BtnSubmit'). click (function (){
If ($ ('# txtUserName'). val () = 'admin' & $ ('# txtPassWord'). val () = '000000 ')
{Alert ('login successful! ');}
Else {alert ('login failed! ');}
})
})
</Script>
</Head>
<Body>
Username: <input id = "txtUserName" type = "text" value = "enter username"/> <br/>
Password: <input id = "txtPassWord" type = "text" value = "enter a password"/> <br/>
<Input id = "btnSubmit" type = "button" value = "btnSubmit"/>
</Body>