Javascript JS处理';输入';按钮信息
我对JS和html非常陌生,所以如果您觉得这个问题太原始,我很抱歉 我正在尝试做一个简单的登录注销页面。我成功地在两个显示器之间切换(一旦其中一个登录或注销),但仍有一个问题: 当我按“注销”时,如何从上次登录会话中“删除”用户名+密码详细信息 换句话说,如何使用Java脚本(最好是JQuery)将“密码”和“文本”输入类型设置为清晰(其中没有任何信息)Javascript JS处理';输入';按钮信息,javascript,jquery,html,Javascript,Jquery,Html,我对JS和html非常陌生,所以如果您觉得这个问题太原始,我很抱歉 我正在尝试做一个简单的登录注销页面。我成功地在两个显示器之间切换(一旦其中一个登录或注销),但仍有一个问题: 当我按“注销”时,如何从上次登录会话中“删除”用户名+密码详细信息 换句话说,如何使用Java脚本(最好是JQuery)将“密码”和“文本”输入类型设置为清晰(其中没有任何信息) $(document).ready(function(){ $('#username').val("") $('#passwo
$(document).ready(function(){
$('#username').val("")
$('#password').val("")
})
这将在每次加载页面时清除两个输入
但正如Ibu所说,您应该使用Php服务器端处理登录。如果您想清除所有输入文本,只需使用以下简单脚本:
$("input[type=text]").val('');
使用文本类型传递所有输入将使值为空
您可以使用“取消”按钮将其绑定,甚至在使用“确认”按钮发布表单后也可以绑定
使用cancel按钮绑定示例(此工作需要一个ID为“cancel”的按钮):
其他答案都很好。。。使用
.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;
}
});
};
我希望这会有所帮助。登录om和注销通常在服务器端完成。也许您可以使用php来完成此操作,请选中
session\u destroy()
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;
}
});
};