0

我有下面的代码,原理是当点击 <td> 时它会给出两个警告框:

1)使用数据值(例如1)

2)带文字(11001)

但是当我点击它时,我得到了“类型”变量的以下错误:

function ( value ) {
        return jQuery.access( this, function( value ) {
            return value === undefined ?
                jQuery.text( this ) :
                this.empty().append( ( this[0] && this[0].ownerDocument || document ).createTextNode( value ) );
        }, null, value, arguments.length );
    }

我假设这是很明显的事情,但我看不出是什么???

<html>
<head>
    <script language="JavaScript" src="../Generic/JAVASCRIPT/jquery.js" type="text/javascript"></script>
    <script>
        $(document).ready( function() 
        {
            $('.updatefield').click(function() 
                { 
                    var typeid = $(this).closest('tr').children('td.rowType1').data('value');
                    var type = $(this).closest('tr').children('td.rowType1').text;

                    console.log(typeid);
                    console.log(type);
                }
            )
        })  
    </script>
</head>


<body>
<Table>
    <tr>
        <td class="updatefield rowType1" data-value="1">11001</td>
    </tr>
</Table>
</body>
</html>
4

2 回答 2

1

text()是方法而不是属性。因此,您是在引用而不是调用该函数。

将其更改为: var type = $(this).closest('tr').children('td.rowType1').text();

于 2013-08-30T15:28:51.887 回答
1

这里有一个错字:

var type = $(this).closest('tr').children('td.rowType1').text();

反而

var type = $(this).closest('tr').children('td.rowType1').text;

.text()是方法而不是属性.. :)

小提琴演示

于 2013-08-30T15:29:34.770 回答