2011-11-28 69 views
4

我非常新的JS和HTML,所以我提前抱歉,如果你觉得这个问题太原始..JS处理“输入”按钮信息

我试图做一个简单的登录 - 注销页面。我成功地在两台显示器之间切换(一旦登录或注销),但我仍然有一个问题: 如何从第一次登录会话中删除用户名和密码的详细信息按'注销'?

换句话说,我怎样才能设置'密码'和'文本'输入类型清晰(没有任何内部信息),使用Java脚本,最好与JQuery

+2

登录和注销通常在服务器端完成。 – Ibu

+0

也许你可以使用php来检查'session_destroy()' –

回答

2
$(document).ready(function(){ 
    $('#username').val("") 
    $('#password').val("") 
}) 

这应该每次清除您的两个输入端加载页面。

但正如伊布所说,你应该使用Php serverside来处理登录。

0

如果要清理所有的输入文本只需使用一个简单的脚本,如:

$("input[type=text]").val(''); 

通过所有输入的类型文本将空值。

您可以将此与您的取消按钮或甚至在发布带有确认按钮的表单之后进行绑定。

与取消按钮例如绑定(您需要一个按钮ID =“取消”这项工作):

$("#cancel").click(function() { 
    $("input[type=text]").val(''); 
}); 
0

其他的答案都是很好的...使用.val('')会做的伎俩。

我打算超出你所要求的范围,因为它可能对你和其他读者有用。这里有一个通用的表单重置功能...

function resetForm(formId) { 

    $(':input', $('#' + formId)).each(function() { 
     var type = this.type; 
     var tag = this.tagName.toLowerCase(); // normalize case 

     if (type == 'text' || type == 'password' || tag == 'textarea') { 
      // it's ok to reset the value attr of text inputs, password inputs, and textareas 
      this.value = ""; 
     } else if (type == 'checkbox' || type == 'radio') { 
      // checkboxes and radios need to have their checked state cleared but should *not* have their 'value' changed 
      this.checked = false; 
     } else if (tag == 'select') { 
      // select elements need to have their 'selectedIndex' property set to -1 (this works for both single and multiple select elements) 
      this.selectedIndex = -1; 
     } 
    }); 
}; 

我希望这有助于。