我正在尽我所能使这有意义,但基本上我有一个文本输入,当用户键入内容并按下回车键时,jQuery搜索XML文档以查找匹配项,并输出其内容。当你第一次尝试时,它完美地工作,但奇怪的是,它每隔一段时间才能正常工作。所以,在第一次尝试时,它会输出正确的文本,第二次,它会像没有找到匹配一样(即使它应该),并在第三次,它再次工作。这种模式重复。我不知道从哪里开始解决这个问题,所以有人有什么想法吗?这里是我的代码:为什么我的jQuery代码每隔一段时间只提交一次Ajax请求?
包含从XML文档输出的文本$("#helpopen input").bind('keypress', function(e) {
if (e.keyCode==13) {
var typed = $("#helpopen input").val();
$("#openresult").slideUp(function() { $(this).remove(); });
$("#aniloa").show().animate({ opacity: 1 });
$.get('/wp-content/themes/kymt/style/js/filetypes.xml', function(d) {
$(d).find('ext').each(function() {
var $ext = $(this);
var curext = $ext.attr("type");
var curtext = $ext.text();
if (typed == curext) {
$("#helpopen div div").append("<p id='openresult' style='display:none'><strong>A ."+typed+" file...</strong><br />"+curtext+"</p>");
$("#openresult").slideDown();
return false;
}
});
});
$("#aniloa").animate({ opacity: 0 }, function() { $(this).hide(); })
}
});
“#aniloa”指的是一个简单的GIF指示载荷,“#openresult”是AP元素,以及“#helpopen DIV DIV”是“#openresult”的父母。
任何机会,您可以发布一个链接的网页与此代码? – 2011-05-09 01:46:28
@David这里是链接:[link](http://www.knowyourmactuts.com/)。只需点击顶部的“我怎么打开...”按钮。 – 2011-05-09 21:14:03
还有一件事,对于XML,您可以输入迄今添加的任何文件类型,请尝试“doc”,“png”或“jpg”。 – 2011-05-09 21:16:16