追加与jQuery的链接 [英] Appending a link with Jquery

查看:195
本文介绍了追加与jQuery的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个链接,具体取决于你已经在哪一页我的网页。我使用Squarespace建立这个网站,所以我做这将是JavaScript或jQuery的最简单的方法。

I'm trying to add a link to my page depending on what page you're already on. I'm using Squarespace to build this site, so the easiest way for me to do this would be with Javascript or Jquery.

我觉得有什么不对这个语法,我失踪。我已经尝试过打出来了\\引号的,但没有奏效。如果我只是在输出文本,它工作正常,但它似乎打破,当我试图使它的链接工作。

I think there is something wrong with this syntax that i'm missing. I already tried to break out of the quotes with a \, but that wasn't working. If I'm just outputting text, it works fine, but it seems to break when I try and make it work with a link.

 if(loc == pageOne) {
$("#pages").append("<div> <a href=\"http://design.optimus.com/projects?currentPage=2\">Next Page</a> </div>")
    }else{
  if(loc == pageOneB){
    $("#pages").append("<div> <a href=\"http://design.optimus.com/projects?currentPage=2\">Next Page</a> </div>")
  }else{
    if(loc == pageTwo){
     $("#pages").append("<div> <a href=\"http://design.optimus.com/projects\">Previous Page</a></div> ")
  }
 }
}

编辑:我只是检查,并链接似乎在Chrome中可以工作,但不火狐

I just checked, and the links seem to be working in Chrome, but not Firefox.

另一个编辑:所以链接在Safari工作压力太大。我想现在的问题是,为什么不能在Firefox?是否有一些关于这种方法是Firefox不支持?

Another So the link is working in Safari too. I guess the issue now is why not in Firefox? Is there something about this method that Firefox doesn't support?

推荐答案

您code似乎很好地工作,但是你可以使用否则,如果语句代替嵌套如果语句:

Your code seems to work fine however you can use else if statements instead of nested if statements:

if(loc == pageOne) {
    $("#pages").append("<div> <a href=\"http://design.optimus.com/projects?currentPage=2\">Next Page</a> </div>")
} else if (loc == pageOneB){
    $("#pages").append("<div> <a href=\"http://design.optimus.com/projects?currentPage=2\">Next Page</a> </div>")
} else if (loc == pageTwo){
    $("#pages").append("<div> <a href=\"http://design.optimus.com/projects\">Previous Page</a></div> ")
}​

下面是一个演示: http://jsfiddle.net/Rba6w/

这篇关于追加与jQuery的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆