2014-12-07 77 views
0

我想使用動態jquery從文本框中獲取數據。它應該像是如果我點擊更新按鈕它應該打開一個警報對話框與在相應的文本框中的文本框中輸入的值,但我的程序不是wokrking。首先它不是從文本框中獲取數據,其次它不是從corrresponding文本框中獲取數據如何使用jquery從文本框中獲取動態數據?

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<html> 
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
<script> 
$(document).ready(function() { 
    $("table tr td input[type='button']").click(function() { 
$(this).closest('tr').find('td').first().find('input[type="text"]').prop('disabled', false); 
}); 
}); 
//=========================================== 

$(document).ready(function(){ 
$('.chkUpdate').on('click', function(){ 
    // var serverName =document.getElementById("servername").value; 
    // var app = document.getElementById("app").value; 
    //var other = $(this).text(); 
    var other = $(this).text(); 
    alert(other);  
    }); 
}); 

</script> 
</head> 
<table> 
<tr> 
    <td> <input type="text" disabled value="Edit"/> </td>  
    <td> <input type="button" name="test" value="Edit"/> </td> 
    <td> <input type="submit" name="test" class="chkUpdate" value="update"/> </td> 

</tr> 
<tr> 
    <td> <input type="text" name="test" disabled value="Edit"/> </td> 
    <td> <input type="button" name="test" value="Edit"/> </td> 
    <td> <input type="submit" name="test" class="chkUpdate" value="update"/> </td> 
</tr> 
<tr> 
    <td> <input type="text" name="test" disabled value="Edit"/> </td> 
    <td> <input type="button" name="test" value="Edit"/> </td> 
    <td> <input type="submit" name="test" class="chkUpdate" value="update"/> </td> 
</tr> 
</table> 
</html> 
+0

與文本使用VAL()不是文本( – 2014-12-07 02:50:52

+0

@穆罕默德·優素福沒有運氣這是給該字段即更新的價值,並沒有文字我輸入 – amol 2014-12-07 02:55:54

回答

0
$(document).ready(function() { 
    $("input[type='button']").click(function() { 
     $(this).parent().parent().find('td').first().find('input[type="text"]').attr('disabled', false); 
     alert($(this).parent().parent().find('td').first().find('input[type="text"]').val()); 
}); 
}); 

,或者您可以使用)像

$(document).ready(function() { 
     $("input[type='button']").click(function() { 
      $(this).parent().prev().find('input[type="text"]').attr('disabled', false); 
      alert($(this).parent().prev().find('input[type="text"]').val()); 
    }); 
    }); 
+0

感謝這個人,至少可以幫助我從文本框中獲取數據並顯示在警報 – amol 2014-12-07 03:00:47

+0

@amol很高興它幫助..好運 – 2014-12-07 03:05:02

0

基本上,從我所看到的,你的檢查更新功能試圖從this文本(值),這是更新按鈕。您需要創建一些方法,讓按鈕可以確定哪些輸入/文本需要更新。

您在輸入按鈕中使用的代碼非常光滑,您可以在檢查更新提交按鈕中使用類似的東西。

另外,由於這兩個事件處理程序都在文檔/就緒代碼中,因此將其作爲單個文檔準備就緒。

相關問題