从动态表

时间:2016-04-11 14:20:34

标签: javascript java html mysql jsp

我需要帮助。我有一张动态表:

while (result.next()) {
    out.write("<tr>");
    for (int i=1; i<=columns; i++) {
        out.write("<td>" + result.getString(i) + "</td>");
    }
    out.write("</tr>");
}

单击该表的行,需要打开新页面或窗口,表1列包含该行的数据。我该怎么办?

1 个答案:

答案 0 :(得分:0)

你可以这样做。将事件附加到表中的每个tr。

while (result.next()) {
    out.write("<tr class="table-row">");
    for (int i=1; i<=columns; i++) {
        out.write("<td>" + result.getString(i) + "</td>");
    }
    out.write("</tr>");
}

$('.table-row').on('click', function(){
    var values_array = [];
    var td_values = "";
    var tr_children = $(this).find('td').each (function() {
         values_array.push($(this).html());
    });

    $.each(values_array, function(value){
       td_values += "value1="+ value +"&";
    });

    // create a query string with the values and send to a new page like this
    // you can concatenate the values to the 
    window.location.replace("http://page?"+td_values);
});
相关问题