這只是一個示例,我正在編寫jQuery程序,它似乎是我使用的一些功能的更好路線。反正這是問題。在我的第二個div上,點擊編輯按鈕,當我點擊編輯按鈕時,我想提醒文本框的值。Jquery Multiple Divs
是的,這可能是重複的,但是從其他堆棧問題的答案已經說我使用類而不是Id。我有,但jquery隻影響第一個div。當我點擊第一個div上的編輯它警告251.但是,當我點擊第二個div上的編輯警報251我希望它提醒351.謝謝堆棧。
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
$(document).ready(function(){
$('.editdet').click (function() {
alert($('.addet').val());
});
});
</script>
</head>
<body>
<div class = "newbox">
<form class = "something">
<table>
<tr>
<td>
<input type="text" id="addet" class = "addet" value="251"/>
<input type="button" id="editdet" class = "editdet" value="Edit"/>
</td>
</tr>
</table>
</form>
</div>
<br>
<div class = "newbox">
<form class = "something">
<table>
<tr>
<td>
<input type="text" id="addet" class = "addet" value="351"/>
<input type="button" id="editdet" class = "editdet" value="Edit"/>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
無效的標記重複相同的ID。 – Jai
我應該在輸入中沒有ID嗎?只用課堂? –
絕對................!對於每個元素,id都是唯一的,無論輸入或divs或表等。 – Jai