开发者

make a simple login page

开发者 https://www.devze.com 2023-01-21 15:47 出处:网络
hey all.. i want to make a simple login page. I have prepared two textfield. <input type=\"text\" id=\"user\">

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:

  1. Anyone with half a brain can look at your JavaScript and see what the id/pw is
  2. I always think it's better to do the user authentication at the server side
  3. 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');
});
0

精彩评论

暂无评论...
验证码 换一张
取 消