双条件jQuery函数事件 [英] Double conditional jQuery function event

查看:67
本文介绍了双条件jQuery函数事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何指定第二种条件,要求用户不仅要单击链接,还要在div之间的区域中单击才能进入landing.html?

How do I specify a second condition that requires that the user not only click a link but click in the area between a div in order to go to landing.html?

<script src="http://code.jquery.com/jquery-1.5.1.min.js"></script> 

<script language="JavaScript" type="text/javascript"> 
    $(document).ready(function () {

        $("#postos").click(function() { 
            $("#linkos").attr('href', 'landing.html');
        });

        $('#clickdiv div').click(function () { 
            $("#linkos").attr('href', 'landing.html');
        });

    });


</script>

<a id="postos" href="#"></a>

<div id="clickdiv">please click</div>

<a id="linkos" href='javascript:window.alert("click the link and div");'><br/><img src="pic.png"></a>

推荐答案


强烈 建议您采取不同的做法.以这种方式使用div SCREAMS设计不良;更不用说,迫使用户单击多个元素会感到笨拙而乏味.


I STRONGLY suggest you go about this differently. Using divs in this manner SCREAMS poor design; not to mention, forcing users to click multiple elements feels clunky and tedious.

但是,我为您提供了一个执行此操作的示例: http://jsfiddle.net/2q3SQ /27/.

However, I have provided you an example of how to do so: http://jsfiddle.net/2q3SQ/27/.

我还为您提供了另一个可能更有用的示例: http://jsfiddle.net/2q3SQ/28/

I have also provided you with another example that might be more useful: http://jsfiddle.net/2q3SQ/28/

链接(可能会有用):

这篇关于双条件jQuery函数事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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