jQuery .load() 函数在 Firefox 3.6.10 中失败

发布于 2024-09-26 21:55:47 字数 1113 浏览 1 评论 0原文

我是个新手,如果这个脚本还很初级,请原谅。

我正在尝试使用 jQuery 的 .load() 函数在我构建的表达式引擎网站上加载下个月或上个月的事件日历。以下脚本适用于 Chrome、Safari、IE 和 Firefox 4 beta,但在 FF 3.6.10 中失败:

   $('th a.right, th a.left, th a.center').click(function() {
      var navMonth = $(this).attr("title");
      $('#calendar').html('<p style="padding: 102px 120px;"><img src="http://dashboardco-op.org/images/infra/ajax-loader.gif" /></p>');
      $('#calendar').load(navMonth);

});

这是 html:

              <th colspan="1"><a id="mc_prev_month" class="icon left" title="{path='live/calendar'}{prev_month format="%Y/%m"}/">&larr;</a></th>
              <th colspan="5"><a class="center" title="{path='live/calendar'}{next_month format="%Y/%m"}/">{month format="%F %Y"}</a></th>
              <th colspan="1"><a id="mc_next_month" class="icon right" title="{path='live/calendar'}{next_month format="%Y/%m"}/">&rarr;</a></th>

我正在使用 'title' 属性,因为 .load() 不会覆盖'href'——因此页面在新页面中加载,而不是异步加载。

谢谢。

I'm a bit of a newbie, so excuse me if this script is rudimentary.

I'm trying to use jQuery's .load() function to load the next or previous month of an event calendar on an expressionengine site that I have built. The following script works in Chrome, Safari, IE, and Firefox 4 beta, but it fails in FF 3.6.10:

   $('th a.right, th a.left, th a.center').click(function() {
      var navMonth = $(this).attr("title");
      $('#calendar').html('<p style="padding: 102px 120px;"><img src="http://dashboardco-op.org/images/infra/ajax-loader.gif" /></p>');
      $('#calendar').load(navMonth);

});

And here's the html:

              <th colspan="1"><a id="mc_prev_month" class="icon left" title="{path='live/calendar'}{prev_month format="%Y/%m"}/">←</a></th>
              <th colspan="5"><a class="center" title="{path='live/calendar'}{next_month format="%Y/%m"}/">{month format="%F %Y"}</a></th>
              <th colspan="1"><a id="mc_next_month" class="icon right" title="{path='live/calendar'}{next_month format="%Y/%m"}/">→</a></th>

I'm using the 'title' attribute, because .load() doesn't overwrite the 'href'-- therefore the pages load in a new page rather than asynchronously.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏尔 2024-10-03 21:55:47

不确定为什么它可能会在特定浏览器上出现问题,但我确实认为有一种稍微更干净的方法可以完成您的任务。看一下 jQuery 中的这个函数,它可以取消在锚点单击时打开新页面: preventDefault()< /a>

有了这个,您可以将路径放在 href 标记中,如果没有其他原因,它可能会使标记看起来更干净。除此之外,唯一想到的其他事情可能是锚点需要 href 属性(我不认为是这种情况?)或者 FF 3.6 可能以不同的方式处理 title 属性?

Not sure why it might have an issue with a particular browser, but I do think there is a slightly cleaner way to do what your going for. Take a look at this function in jQuery to cancel the opening of a new page on anchor click: preventDefault()

With this, you could put the path in the href tag, if for no other reason than it would probably make the markup look cleaner. Other than that, the only other things that come to mind are perhaps the anchor needs href attribute (I don't think this is the case?) or perhaps FF 3.6 handles the title attribute differently?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文