timeId = setTimeout(function () {
$.post(settings.url, param, function (data) {
var wordObj = $(data);
if (settings.dataType == “xml”) {
var wordNodes = wordObj.find(“word”);
autoTip.html(“”);
wordNodes.each(function (i) {
var divNode = $(“<div>”).attr(“id”, i);
//将遍历的单词加入到创建的div中,然后把该div追加到auto中
divNode.html($(this).text()).appendTo(autoTip);
//鼠标已进去,添加高亮
divNode.mousemove(function () {
//如果已经存在高亮,去掉高亮改为白色
if (index != -1) {
autoTip.children(“div”).eq(index).css(“background-color”, settings.unhighlightColor);
}
index = $(this).attr(“id”);
$(this).css(“background-color”, settings.highlightColor);
});
//鼠标移出,取消高亮
divNode.mouseout(function () {
$(this).css(“background-color”, settings.unhighlightColor);
});
//点击高亮内容
divNode.click(function () {
$this.val($(this).text());
index = -1;
autoTip.hide();
});
});
if (wordNodes.length > 0) {
autoTip.show();
} else {
autoTip.hide();
index = -1;
}
}
});
}, settings.delay);
} else {
autoTip.hide();
index = -1;
}
} else if (kc == keys.UP || kc == keys.DOWN) {/*当用户按下上下键*/
if (kc == keys.UP) {//向上
if (index != -1) {
autoNodes.eq(index).css(“background-color”, settings.unhighlightColor);
index–;
} else {
index = autoNodes.length – 1;
}
if (index == -1) {
index = autoNodes.length – 1;
}
autoNodes.eq(index).css(“background-color”, settings.highlightColor);
} else {//向下
if (index != -1) {
autoNodes.eq(index).css(“background-color”, settings.unhighlightColor);
}
index++;
if (index == autoNodes.length) {
index = 0;
}
autoNodes.eq(index).css(“background-color”, settings.highlightColor);
}
} else if (kc == keys.PAGEUP || kc == keys.PAGEDOWN) {
event.preventDefault();
if (kc == keys.PAGEUP) {
if (index != -1) {
autoNodes.eq(index).css(“background-color”, settings.unhighlightColor);
}
if (autoNodes.length > 0) {
index = 0;
autoNodes.eq(0).css(“background-color”, settings.highlightColor);
}
} else {
if (index != -1) {
autoNodes.eq(index).css(“background-color”, settings.unhighlightColor);
}
index = autoNodes.length – 1;
autoNodes.eq(index).css(“background-color”, settings.highlightColor);
}
} else if (kc == keys.ENTER) {
//回车键
//有高亮内容就补全信息
if (index != -1) {
$this.val(autoNodes.eq(index).text());
} else {//没有就隐藏
$(“body”).append($(“<div/>”).text(“文本框中的【” + $this.val() + “】被提交了!”));










