Javascript rowIndex方法不起作用 [英] Javascript rowIndex method is not working

查看:171
本文介绍了Javascript rowIndex方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用TR的rowIndex属性,但它不起作用。请让我知道如果我在这里做错了什么。

I am using the rowIndex property of TR but it is not working. Please let me know if i am doing something wrong here.

function myMethod(){
                alert ( this.parent.rowIndex  );   // parentNode is also used
            }

Html

<table border="1">
            <tr>
                <td onclick="myMethod();">1.1</td>
                <td>1.2</td>
                <td>1.3</td>
            </tr>
            <tr>
                <td onclick="myMethod();">2.1</td>
                <td>2.2</td>
                <td>2.3</td>
            </tr>
            <tr>
                <td onclick="myMethod();">3.1</td>
                <td>3.2</td>
                <td>3.3</td>
            </tr>
            <tr>
                <td onclick="myMethod();">4.1</td>
                <td>4.2</td>
                <td>4.3</td>
            </tr>
        </table>


推荐答案

this.parent.rowIndex中的this是窗户。不是td元素。
Try

the "this" in this.parent.rowIndex is the window. Not the td element. Try

<td onclick="myMethod(this);">1.1</td>

function myMethod(obj){ alert ( obj.parentNode.rowIndex );} 

这篇关于Javascript rowIndex方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆