hey all.. i want to make a simple login page. I have prepared two textfield.
<input type="text" id="user">
<input type="password" id="password">
<input type="button" id="开发者_如何学Cgo">
i want after click #go script can check:
if #user value != "admin"
then #password value != "qaubuntu"
will show and JS alert. but if data same, will show some hidden . can you show me how to do that?
$(function() {
$('#go').click(function() {
if($('#user').val() !== "admin" || $('#password').val() !== "qaubuntu") {
alert('Invalid login');
return false;
} else {
return true;
}
});
});
that's the quick fix (assuming you're just playing around). But you should never do it like this for a few reasons:
- Anyone with half a brain can look at your JavaScript and see what the id/pw is
- I always think it's better to do the user authentication at the server side
- Probably a million others, it's so insecure it hurts
but for the purpose of this answer I'm assuming you're just practising with jQ.
this is in jquery, when clicking on button #go check the login data
$('#go').bind('click',function()
{
if($('#user').val() == 'admin' && $('#password').val() == 'qaubuntu'))
//ok do what you need
else
alert('username or password not valid');
});
精彩评论