jQuery仅在第二次点击时工作 [英] jQuery working on second click only

查看:84
本文介绍了jQuery仅在第二次点击时工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以指出问题为什么我无法在第一次点击时收到警报弹出窗口?它只能每隔一次点击工作(即在奇数点击时不起作用,偶数次点击工作)。

Can anyone point the issue why I am unable to get the alert popup on first click? It works only every second click (i.e. doesn't work on odd number click and works on even number click).

HTML:

<div class="slider">
    <div class="slider-box ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all">
        <a class="ui-slider-handle ui-state-default ui-corner-all" href="#" style="left: 50%;"></a>
    </div>
</div>

jQuery:

$(document).ready(function() {
    $("a.ui-slider-handle").click(function() {
        alert('test');
    }); 
});

我也试过但没有工作

$(document).ready(function() {
    $("a.ui-slider-handle").mousedown(function() {
        alert('test');
    }); 
});


推荐答案

嗯......你试过阻止默认锚行为? http://jsbin.com/IfirEBOj/2/edit

Hmm... have you tried to prevent the default anchor behavior? http://jsbin.com/IfirEBOj/2/edit

$("a.ui-slider-handle").click(function( event ) {
    event.preventDefault();
    alert('test');
}); 

在任何情况下,您都应该熟悉一些调试工具,看看它会抛出什么错误。如果有的话......

In any case you should get familiar with some debugging tool and see what errors it throws. If any...

这篇关于jQuery仅在第二次点击时工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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