weixin_33704234 2013-02-15 23:34 采纳率: 0%
浏览 38

AJAX / jQuery的锚标签

I am looking to a way to use images as links to new pages inside my web app.

I am using data-file anchor tags to keep the user inside the web app.

<a data-file="salt.html?v=1"><img src="assets/images/template/salt.jpg" width="125" height="125" /> </a>

These tags are inside:

<div class="products_content">

My code looks like this:

$('.products_content a').on('click', function(){  
    $('.products_content a').removeClass('selected');
    $(this).addClass('selected');
    changePage( $(this).attr('data-file') );
});  

Any ideas? I have no idea why it isn't working. I have a similar set up for my navigation and it works fine. My navigation set up is as follows:

<nav>
    <a data-file="home.html?v=1">Home</a>
    <a data-file="about.html?v=1">About Us</a>
    <a data-file="services.html?v=1">Services</a>
    <a data-file="products.html?v=1">Products</a>
</nav>

And:

$('nav a').on('click', function(){
    $('nav a').removeClass('selected');
    $(this).addClass('selected');
    changePage( $(this).attr('data-file') );
});

$('nav a:nth-child(1)').trigger('click');

Any help would be greatly appreciated. I am in over my head.

  • 写回答

1条回答 默认 最新

  • weixin_33736832 2013-02-15 23:50
    关注

    Works for me in jsFiddle. Are any errors showing up in the console? Is your selector finding the anchors to begin with? Is the click event even getting fired? Is the changePage() method being included in that page somewhere?

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题