2013-08-30 59 views
0

我有下面的代码,该原则是在< TD当点击>它给出了两个警报框:从jQuery的。点击功能奇怪的错误消息话题

1)与数据值(例如1)

2)与文本(11001)

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

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> 

回答

1

一个错字这里:

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

代替

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

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

Fiddle Demo

+0

看,我知道这是明显的事情,欢呼...... – IGGt

1

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

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

+0

感谢您的回复,我不能相信我错过了(周五晚上 - 这是我的借口)。干杯。 – IGGt