当我单击它时,我试图获取一行的值,但即使我单击其他 tr,它也只会获取第一个 tr 的值。如何获得我点击的 tr 的值?
我用 jsonresponse 填满我的表。这是我的代码。
这是我的代码。
注册.html
<table class="table table-striped table-hover table-bordered" style="width:100%" border="0" id="miembrotb">
JsonResponse.js
$("#buscar_paciente").click(function(e) {
var completo = $("#nombre").val();
var input_string = completo;
$.ajax({
url: "/datospacientejson",
type: "POST",
dataType: "json",
data: {
nombre: input_string,
csrfmiddlewaretoken: '{{ csrf_token }}'
},
success: function (json) {
var jsonResponse = eval(json);
$("#miembrotb").empty();
$("#miembrotb").append('<tr><th>ID</th><th>NOMBRE</th><th>FECHA DE NACIMIENTO</th></tr>');
$.each(jsonResponse, function (index, element) {
html = '<tr><td class="td1">'+jsonResponse[index]["fields"]["folio"]+'</td><td>'+jsonResponse[index]["fields"]["nombre"]+' '+jsonResponse[index]["fields"]["apellido_paterno"]+'<td>'+jsonResponse[index]["fields"]["fecha_nacimiento"]+'</td>'+'</tr>'
$("#miembrotb").append(html);
});
},
error: function(xhr, errmsg, err) {
alert(xhr.status + "ERROR EN BUSQUEDA DE INFORMACION DEL PACIENTE: " + xhr.responseText);
}
});
return false;
});
//ON CLICK FUNCTION
$("#miembrotb").click(function(){//click anywhere in a row
alert($(this).find("tr").html());
});