2011-11-28 70 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; 
     } 
    }); 
}; 

我希望這有助於。