jQuery .on()抛出Uncaught TypeError:undefined不是函数

时间:2014-07-24 15:53:30

标签: javascript jquery

也许我看不到这个。

鼠标悬停工作正常。 mouseout会生成错误“Uncaught TypeError:undefined is not a function”。

$(document).ready(function(){
    $("tr").on("mouseover", function(){ highlightRow(); });
    $("tr").on("mouseout", "lowlightRow");
});

function highlightRow() {
    console.log("highlightRow");
}

function lowlightRow() {
    console.log("lowlightRow");
}

感谢。

3 个答案:

答案 0 :(得分:5)

您需要传递一个功能。在函数名称周围加上引号使其成为字符串文字而不是变量。删除它们。

$("tr").on("mouseout", lowlightRow);

答案 1 :(得分:1)

$("tr").on("mouseout", lowlightRow);   // <-- passes function reference

$("tr").on("mouseout", "lowlightRow"); // <-- passes string

答案 2 :(得分:1)

   $("tr").on("mouseout", "lowlightRow");

应该是

   $("tr").on("mouseout", lowlightRow);
相关问题