0
내 데이터베이스의 날짜를 삭제하기위한 내 TD의 값을 취득 할
이 내 코드입니다 :
$(document).ready(function()
{
$('table#delTable td a.delete').click(function()
{
if (confirm("Eliminare il record?"))
{
var id = $(this).parent().parent().attr('id');
var numero = $("#unico").text();
id = numero;
var data = 'id=' + id;
var parent = $(this).parent().parent();
$.ajax(
{
type: "POST",
url: "Database",
data: data,
cache: false,
success: function()
{
parent.fadeOut('slow', function() {$(this).remove();});
}
});
}
});
$('table#delTable tr:odd').css('background',' #FFFFFF');
});
</script>
</head>
<body>
<%
final String selezione = ("SELECT * FROM anagrafica");
ConnectionManager cm = new ConnectionManager();
ResultSet rs = null;
try {
Statement st = (Statement) cm.getConnection().createStatement();
rs = st.executeQuery(selezione);
out.print("<table align='center' cellpadding='5' cellspacing='0' width='30%' id='delTable' bgcolor='#f6f6f6' style='border:1px solid #cccccc;'>");
out.print("<table align='center' cellpadding='5' cellspacing='0' width='30%' id='delTable' bgcolor='#f6f6f6' style='border:1px solid #cccccc;'>");
out.print("<tbody><tr>");
out.print("<th align='left' style='border-bottom:1px solid #cccccc;'><strong>Nome</strong></th>");
out.print("<th align='center' style='border-bottom:1px solid #cccccc;'><strong>Cognome</strong></th>");
out.print("</tr>");
while (rs.next()) {
out.print("<tr width id='1' style='background: rgb(255, 255, 255);'>");
out.print("<td align='left'>"+rs.getString("Nome")+ "</td>");
out.print("<td align='center'>"+rs.getString("Cognome")+ "</td>");
out.print("<td style = 'display:none' id = 'unico' align='right'>"+rs.getInt("Id_unico")+ "</td>");
out.print("<td align='center'><a href='#' class='delete' style='color:#FF0000;'><img alt='' align='absmiddle' border='0' src='delete.png'>"+"</a></td>");
}
out.print("</tr>");
out.print("</tbody></table>");
} catch (SQLException sqle) {
sqle.printStackTrace();
} finally{
try {
if(cm.getConnection()!=null) cm.getConnection().close();
rs.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
%>
하지만 3 개 td
행이있는 경우 어떤 포함 : 1, 2, 3 첫 번째 행을 클릭하면 데이터베이스가 unique (1) ID를 가진 레코드를 삭제하고 OK,
두 번째 행을 클릭하면 항상 id 1이 삭제됩니다. 값이 항상 첫 번째 행에 대해 30 행이있는 경우
td 내에서 반복해야합니다. 어떻게 HTML 요소를 반복 할 수 있습니까? id
변수 초기화
var id = $(this).parent().parent().attr('id');
var numero = $("#unico").text();
id = numero;
먼저 한 다음에 아무것도하지 않고 :
사이드 노트 :'$ (this) .parent()'로 DOM 구조에 의존하지 않고'$ (this) .closest ('tr')'를 사용하십시오. –
소스가 아닌 출력 HTML을 게시하면 더 나은 결과를 얻을 수 있습니다. 브라우저를 사용하여 페이지로 저장하십시오. –
js를 작동시키기 전에 html을 정리해야합니다 : '
답변
귀하의 문제는 여기에있다. 이후에
numero
변수를 만들고id
값을numero
값으로 덮어 씁니다. 나는 당신의$("#unico").text();
은 가정입니다 1.당신이 할 것은 이것과 같다 :
출처
2014-11-05 12:27:33 vaso123
오른쪽 당신이, 내가로 변경, 나는 몇 가지 시도를하고 이후를 제거하려면 잊어 버린 감사 :
var id = $("#unico").text();
하지만 문제는 여전히 발생합니다.출처
2014-11-05 12:43:35 Chrix1387
관련 문제