table 新增 tr 的點選事件
阿新 • • 發佈:2019-01-08
在<table表格中為每一個<tr新增一個點選或雙擊事件,並傳引數:
方法傳參可以通過直接傳參,也可以通過物件傳參:如下:
HTML程式碼:
<table id="contentTable" class="table table-bordered table-condensed"> <thead> <tr> <th>狀態</th> <th>檔案編號</th> <th>客戶姓名</th> <th>性別</th> <th>年齡</th> <th>手機號碼</th> </tr> </thead> <tbody> <c:forEach items="${page}" var="customer" varStatus="custIndex"> <tr id ='id_${custIndex.index}' onclick="setCustomerNumber('${custIndex.index}','${customer.customerNumber}',this)" ondblclick="selectCustomerDb(this)"> <td> <span> ${fns:getDictLabel(customer.perfectStatus,'perfect_status' ,'' ) } </span> </td> <td> <a href="${ctx}/cust/customer/custArchives?customerNumber=${customer.customerNumber} &archivesId=${customer.archivesId}&perfectStatus=${customer.perfectStatus}&flagId=${customer.flagId}"> ${customer.treatmentArchivesNumber} </a> </td> <td> ${customer.customerName} </td> <td> ${fns:getDictLabel(customer.sex,"sex" ,'' ) } </td> <td> ${customer.age} </td> <td> ${fns:encodeMobile(customer.mobile)} </td> </tr> </c:forEach> </tbody> </table>
JS:
//單擊事件(左擊)
function setCustomerNumber(index,customerNumber,tr){
// tr.cells [0]:獲取當前行中的第一列,
// tr.cells [0] .childNodes [1] .innerHTML:獲取當前行中間span標籤中的值trim( ):去空
var status = tr.cells [0] .childNodes [1] .innerHTML.trim();
var name = tr.cells [2] .innerHTML.trim(); //獲取當前行的客戶姓名
}
//雙擊事件
function selectCustomerDb(tr) { }