【发布时间】:2011-09-10 03:57:01
【问题描述】:
我需要从 JavaScript 函数中获取行号:
function cap_check(){
var row;
$('td').change(function(){
row = $(this).parent().parent().children().index($(this).parent());
alert(row);
});
alert(row);
}
在函数内,row 被正确警告。函数外是undefined。
【问题讨论】:
-
看看这篇文章。这是相同的。 stackoverflow.com/questions/2611980/…
-
能否请您包含此代码附带的 html
-
@JAiro:不,不一样。
-
你期待什么?当函数
cap_check被调用时,并不意味着change事件处理函数被立即触发。意思是,row = $(this).parent()....将在cap_check已经返回后的一段时间后执行。
标签: javascript jquery