Jquery 和 Safari
我在使用 JQuery 和 Safari(Windows 版本)时遇到问题。 该代码适用于 FF/IE7/Chrome,但不适用于 Safari。
我有一个简单的
,其中嵌入了
- 单击
div
,但在 Safari 中不行。HTML:
<ul>
<li>something</li>
<li>something2</li>
<li class="more">
<a href="" class="moreFacetsLink">Click to see more options</a>
<div class="moreFacets">bunch of text</div>
</li>
</ul>
这是 JQuery 代码:
$('.moreFacetsLink').click(function () {
$(this).siblings('div').toggle();
});
对于这里可能发生的事情有什么想法吗? 再说一遍 - 这似乎适用于所有其他浏览器!
我是 JQuery 的新手。
谢谢!
I'm having an issue with JQuery and Safari (Windows Version). The code works on FF/IE7/Chrome but not Safari.
I have a simple <li>
that has a <div>
embedded in to - clicking the <li>
should expose the hidden div
, but not in Safari.
The HTML:
<ul>
<li>something</li>
<li>something2</li>
<li class="more">
<a href="" class="moreFacetsLink">Click to see more options</a>
<div class="moreFacets">bunch of text</div>
</li>
</ul>
Here is the JQuery code:
$('.moreFacetsLink').click(function () {
$(this).siblings('div').toggle();
});
Any thoughts as to what may be going on here? Again - this seems to work on all other browsers!
I'm a newbie when it comes to JQuery.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的 HTML 粘贴准确度如何?
您从未关闭过您的“moreFacetsLink”锚标记,这可能使 Safari 认为它已隐式关闭,并且“一堆文本”被一个额外的、无 HREF 的无类未关闭的锚标记包围...事实证明这:
... 使用您提交的标记执行您想要的操作。
正确关闭您的锚标记(包含 href 属性的奖励点),您应该可以开始了。
How accurate is your HTML pasting?
You never closed your "moreFacetsLink" anchor tag, which probably makes Safari think that it was implicitly closed, and the "bunch of text" is surrounded by an additional, HREF-less Class-less Unclosed anchor tag... evidenced by the fact that this:
... does what you want with your submitted markup.
Close off your anchor tag properly (bonus points for including the href attribute) and you should be good to go.
href="" 正在 safari 中重新加载您的页面
我会尝试使用 css 为其添加下划线和样式,并删除空的 href。
href="" is reloading your page in safari
I would try using css to underline and style it, and drop the empty href.
我很确定您需要从点击函数中返回 false; 来取消链接点击。
I'm pretty sure you need to
return false;
from the click function to cancel the link click.首先,您需要检查浏览器是否正在执行回发,如果这是真的,您可以像这样避免它
尝试:
$(e.target)
而不是这个$(this)
这可能是一种不同的方式
希望这有帮助
First you need to check if the browser is doing postback and if this is true you can avoid it like this
try this:
$(e.target)
instead of this$(this)
this could be a different way
hope this helps