我有这样简单的代码:
function currentImageKey() {
$('#akslide ul li.active').index();
}
Run Code Online (Sandbox Code Playgroud)
如果我只是在控制台中调用该函数,我会得到"未定义".否则,如果我直接运行函数的内容,就像这样
$('#akslide ul li.active').index();
Run Code Online (Sandbox Code Playgroud)
它有效,我得到索引.
为什么不起作用?非常感谢您的帮助.
Que*_*tin 10
该函数没有return语句,因此返回undefined.
加一个.
function currentImageKey() {
return $('#akslide ul li.active').index();
}
Run Code Online (Sandbox Code Playgroud)