2015-06-21 43 views
-3

我寫了一個簡單的jQuery,使按鈕的點擊,但textboxes一個錯誤,當我點擊,一秒鐘的文本框使然後進入禁用狀態再次存在與啓用禁用文本框

代碼:

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>Profile Page</title> 
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script> 
<script src="//malsup.github.com/jquery.form.js"></script> 
    <script> 
     $(function(){ 
      $("#edit").click(function() { 
       $('*').prop('disabled',false); 
       }); 
      }); 
    </script> 
</head> 
<body> 
<center><h1>User Profile</h1></center><br><br> 

<form action="" method="post"> 
<table> 
<tr> 
    <td> User ID </td> <td> <input type="text" name="uid" disabled> 
</td> 
</tr> 
<tr> 
<td>First Name </td> <td><input type="text" name="fname" disabled> </td> 
</tr> 
<tr> 
<td> Last Name </td> <td><input type="text" name="lname" disabled> </td> 
</tr> 
<tr> 
    <td> Email </td> <td><input type="text" name="email" disabled> </td> 
</tr> 
<tr> 
<td> Country </td> <td><input type="text" name="country" disabled> </td> 
</tr> 
<tr> 
    <td> <input type="Submit" value="Edit" id="edit"> </td> 
    <td> <input type="Submit" value="Update" onclick="update()"> </td> 
</tr> 
</table> 
</form> 

</body> 
</html> 

我還添加了JSON罐子在圖書館

+0

確定了你的觀點..thnks很多人 –

+0

你應該防止默認行爲發生 – Liquidpie

回答

1

你的點擊處理程序不取消按鈕,這是提交表單的默認行爲。表單的動作是空白的,所以提交基本上會重新加載頁面。

你可以改變的按鈕,這樣它不是一個提交按鈕(,因此沒有默認行爲):

<input type="button" value="Edit" id="edit"> 

或者你可以改變你的JS取消默認行爲:

$("#edit").click(function (e) { 
    e.preventDefault(); // <-- add this, and add the 'e' argument to the function 
    $('*').prop('disabled',false); 
}); 
+0

thnks人..現在 –

0

這是監守你使用<input type='submit'...

請使用<input type='button'....,你將能夠使所有的輸入框。

隨着type=submit形式被提交和頁面重新裝入,因此輸入框的屬性「已禁用」再次應用。

希望這會有所幫助!

+0

工作thnks很多人 –

+0

'請使用