weixin_33688840 2014-06-01 03:00 采纳率: 0%
浏览 16

jQuery URL哈希输入刷新

        $( "ul#results" ).click(function() {$( this ).slideUp();});

I'm using the code in the following tutorial: http://ninetofive.me/blog/build-a-live-search-with-ajax-php-and-mysql Above is my jQuery code targeting the AJAX dropdown.

I'm trying to make the dropdown fade away when the user clicks on a link, without having the page redirect or refresh. I'm also using hashes in the URL (handled server side) for my link. For instance:
mysite.com/#selecteddropdowndata

I'm not sure whether the problem is with my URL hashes, jQuery or a combination.

  • 写回答

2条回答 默认 最新

  • weixin_33739541 2014-06-01 03:14
    关注

    here is a link to a working jsfiddle: http://jsfiddle.net/Grimbode/6zAYq/2/

    If you click on a link ( ) you need to prevent the default click event to go off, and trigger the one you actually want.

    html:

    <ul id="results">
        <li><a href="www.google.com">test123</a></li>
        <li><a href="www.google.com">test123</a></li>
        <li><a href="www.google.com">test123</a></li>
    </ul>
    

    js:

    $( "a" ).on('click', function(e){
        e.preventDefault();
        $('#results').trigger('click');
    });
    
    $('#results').on('click', function(e){
        $( this ).slideUp();
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名