所以我根据用户点击的内容更新 div 的内容。有时我显示图像,有时我显示文本:
var output;
switch(type)
{
case IMAGE:
pages = null;
contentText = null;
upArrow = null;
downArrow = null;
var imageURL = "assets/images/" + items[itemIndex].imageURL;
output = '<img src="' + imageURL + '" class="fullImage" />';
break;
case TEXT:
pageIndex = 0;
pages = items[itemIndex].copy.page;
numPages = pages.length;
lastPageIndex = numPages - 1;
output = '<div id="contentText" class="text"></div>';
output += '<div id="textUpArrow" class="arrow upArrow"></div>';
output += '<div id="textDownArrow" class="arrow downArrow"></div>';
contentText = $("#contentText");
textUpArrow = $("#textUpArrow");
textUpArrow.bind(MOUSE_DOWN, onUpArrowClicked);
textDownArrow = $("#textDownArrow");
textDownArrow.bind(MOUSE_DOWN, onDownArrowClicked);
setText();
break;
}
content.html(output);
这个问题似乎与范围有关。我在我的 JS 文件的根级别声明了 contentText、textUpArrow 和 textDownArrow(我不知道它是否被称为 root,但它在每个函数之外,所以它是全局可用的)。
发生的事情是当我在控制台中输出上述变量时,没有任何东西是未定义的。但是,每当我尝试使用这些变量时,无论是用于事件侦听器还是通过 jQuery 更改它们的 CSS,都没有任何反应。
我应该调查什么?谢谢!