0

I have the below code, the principle being that when clicking on the < td > it gives two alert boxes:

1)with the data-value (e.g. 1)

2) with the text (11001)

but when I click on it I get the follwoing error for the 'type' variable:

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 );
    }

I'm assuming it is something quite obvious, but I can't see what???

<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

ここでタイプミス:

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 に答える
1

text()プロパティではなくメソッドです。したがって、関数を呼び出すのではなく、参照しています。

次のように変更します。 var type = $(this).closest('tr').children('td.rowType1').text();

于 2013-08-30T15:28:51.887 に答える