Jquery Keyup() 示例在服务器上不起作用
我尝试在我进行的一些搜索中使用keyup功能,但是对于服务器上的文件并通过IE8和FF访问页面,keyup功能似乎不起作用。为了测试它,我借用了 jQuery 网站示例中的代码,并将其放在服务器上(Windows Server 2003 R2)。但是,这个示例也不起作用(http://api.jquery.com/keyup/)。我注意到它有一行
我最初的想法是,“我的不是”无法工作,因为我缺少此事件文件!”但谷歌搜索后我认为情况并非如此。在我的代码中,我链接到下载的 jQuery 副本,并且我还尝试通过 googleapi 的副本链接它,但两次都没有成功。关于为什么 keyup 功能可能无法在服务器上运行的任何想法?
I am trying to use the keyup function in a little search I made, but with the files on the server and accessing the page through IE8 and FF, the keyup function doesn't seem to work. To test it I borrowed the code from the jQuery websites example put it on the server (it's Windows Server 2003 R2). However, this example also isn't working(http://api.jquery.com/keyup/). I noticed it has the line
<script type="text/javascript" src="/scripts/events.js"></script>
and my initial thought was, "mine isn't working because I'm missing this events file!" but after googling I'm thinking this isn't the case. In my code I'm linking to a downloaded copy of jQuery, and I've also tried linking it through the googleapi's copy, no luck either time. Any thoughts about why the keyup function might not be working on the server?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该页面上的代码似乎有点损坏。具体来说,它似乎使用了最新 jQuery 中缺少的
print
函数(也许它包含在缺少的events.js
脚本中?)我做了一些小的更改制作一个工作版本(请注意,我使用的是 Google 托管的 jQuery;您可以将其指向您的本地版本,它应该仍然可以正常工作。)
在这个更改后的版本中,我使用 jQuery 的
append()< /code> 输出函数将调试消息添加到我在文本框下方添加的新
div
中。当您在文本框中键入内容时,您应该会看到在那里注册了按键事件。The code on that page seems a little broken. Specifically, it seems to use a
print
function that's absent from the latest jQuery (perhaps it's included in that missingevents.js
script?)I've made some small changes to make a working version (note I'm using the Google-hosted jQuery; you can point that at your local version instead and it should still work fine.)
In this changed version, I'm using jQuery's
append()
function to output the debugging messages into a newdiv
I've added below the text box. When you type into the text box, you should see the key press events being registered there.您正在观看的元素是否在页面加载后动态生成?如果是这样,您需要使用 live:
否则尝试:
另外,请确保您选择正确的元素(输入框?)并仔细检查选择器是否正确。在不同的浏览器中,无论是否处理 e.keyCode,都可能会出现一些问题。如果 e.keyCode 不存在,上面的示例还会检查 e.which 中的键代码值。
Does the element you're watching get generated dynamically, after page load? If so you'll need to use live:
Otherwise try:
Also, make sure you are selecting the proper element (input box?) and double check the selector is correct. Some problems might arise in different browsers, handling e.keyCode, or not. The above example also checks for a key code value in e.which, if e.keyCode does not exist.