jQuery ie 输入文本问题
当用户按回车键时,我想在搜索栏中显示“正在加载 gif”,我遇到以下奇怪的问题。该代码适用于本地主机上的 mozilla 和 ie 7,但仅适用于我的 cpanel 上的 mozilla... 你有什么线索吗?抱歉,如果这看起来很明显:) 这是代码,路径是动态的,但当然是正确的:
$('#searchField').focus(function(){
$(this).keypress(function(event) {
if ( event.which == 13 ) {
$(this).css('background-image', 'url("/dvt/public/images/ajaxLoader.gif")');
}
});
});
非常感谢
I have the following weird issue with the "loading gif" that I want to display in my search bar when the user hits enter. The code works on mozilla and ie 7 on the localhost but only on mozilla on my cpanel...
Do you have any clue?? Sorry if this looks obvious :)
here is the code, the path is dynamic but of course correct:
$('#searchField').focus(function(){
$(this).keypress(function(event) {
if ( event.which == 13 ) {
$(this).css('background-image', 'url("/dvt/public/images/ajaxLoader.gif")');
}
});
});
thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
把它放在你的事件中:
IE 和 Firefox 中是不同的
Put this to get your event :
It's different in IE and firefox
就您的图像而言,在我看来,图像的 URL 将是
/images/ajaxLoader.gif
因为/dvt/public
似乎是文档根路径。当图像在你的服务器上时,你在浏览器中输入什么 URL 来查看它?另外,您可以从 CSS 中的url()
中取出双引号。对于事件和键码,更改事件参数的名称(首先尝试使用
e
)以避免与全局命名空间发生冲突,然后使用e.which
,按照 < a href="http://api.jquery.com/keypress/" rel="nofollow">jQueryfn.keypress 文档。As far as your image, it seems to me that the URL to the image would be
/images/ajaxLoader.gif
as/dvt/public
seems like a doc root path. With the image on your server, what URL do you put in the browser view it? Also, you can pull the double quotes out of theurl()
in the CSS.For the event and keycode, change the name of your event parameter (try
e
for starters) to avoid collision with the global namespace, then usee.which
, per the jQueryfn.keypress docs.