Php 正在查找表中单击的行数

Php 正在查找表中单击的行数,php,javascript,mysql,Php,Javascript,Mysql,我找到了一个代码,该代码获取单击的行数,但我无法理解它 有人能解释一下下面的代码吗 <html> <head> <title>Row indexes</title> <script type="text/javascript"> onload = function() { if (!document.getElementsByTagName

我找到了一个代码,该代码获取单击的行数,但我无法理解它

有人能解释一下下面的代码吗

<html>
    <head>
        <title>Row indexes</title>
        <script type="text/javascript">
            onload = function() {
                if (!document.getElementsByTagName || !document.createTextNode) return;
                var rows = document.getElementById('my_table').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
                for (i = 0; i < rows.length; i++) {

                    rows[i].onclick = function() {
                        alert(this.rowIndex + 1);
                    }
                }
            }
        </script>
    </head>
        <body>
            <table id="my_table">
                <tbody>
                    <tr><td>first row</td></tr>
                    <tr><td>second row</td></tr>
                </tbody>
            </table>
        </body>
</html>
网址是:

// Binding a function to a onload event and invokes it when 
// window is loaded
onload = function () {
    // Checking if the 2 methods are supposted by the browser.
    // If no thne it returns and does nothing
    if (!document.getElementsByTagName || !document.createTextNode) return;
    // Finding the table by id and get the `tbody` tag inside it
    // The get all the tr's based on tagName
    var rows = document.getElementById('my_table')
                 .getElementsByTagName('tbody')[0]
                  .getElementsByTagName('tr');
    // Iterate over all rows and bind a click event
    for (i = 0; i < rows.length; i++) {
        rows[i].onclick = function () {
            alert(this.rowIndex + 1);
        }
    }
}