我创建了一个表并将其从fire base中检索出来。
<table width="100%" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td class="th">Title</td>
<td class="th">First Name</td>
<td class="th">Last Name</td>
<td class="th">Hospital</td>
<td class="th">Spciality</td>
<td class="th">Doctor Fee</td>
<td class="th">Mobile Number</td>
<td class="th">Address</td>
<td class="th">Actions</td>
</tr>
</thead>
<tbody id="doctorlist">
<script>
var rootRef = firebase.database().ref("User/doctor");
rootRef.on("child_added",snap =>{
var fname=snap.child("Firstname").val();
var lname=snap.child("Lastname").val();
var id=snap.child("DoctorID").val();
var dob=snap.child("DOB").val();
var address=snap.child("Doctor_Address").val();
var email=snap.child("E-mail").val();
var mobile=snap.child("Mobile_no").val();
var hometp=snap.child("Home_no").val();
var sex=snap.child("Sex").val();
var hospital=snap.child("Hospital").val();
var slmcno=snap.child("SLMC_Number").val();
var speciality=snap.child("Spciality").val();
var emargancyperson=snap.child("Emargency_person").val();
var emargancyrelationship=snap.child("Emargency_reletionship").val();
var emargancymobile=snap.child("Emargency_TP").val();
var fee=snap.child("Doctor_fee").val();
var nic=snap.child("NICNo").val();
var title=snap.child("Title").val();
//var lname=snap.child("DocotID").val();
$("#doctorlist").append("<tr><td>"+title+"</td><td>"+fname+"</td><td>"+lname+"</td><td>"+hospital+"</td><td>"+speciality+"</td><td>"+"Rs."+fee+".00"+"</td><td>"+mobile+"</td><td>"+address+"</td><td><button>Remove</button></td></tr>");
});
</script>
这是完美的。但是当我点击特定的行时,我想将单元格数据传递给变量。
我用过这个脚本
<script>
var table = document.getElementById('doctorlist');
for (var i = 1; i < table.rows.length; i++) {
table.rows[i].onclick = function() {
//rIndex = this.rowIndex;
alert(this.cells[0].innerHTML + this.cells[1].innerHTML + this.cells[2].innerHTML...........);
};
}
</script>
硬盘故事是可以的,但对此并不起作用。我该怎么解决这个问题?