如果是MouseUp,请停止onclick

时间:2010-08-07 08:36:05

标签: jquery onclick

是否可以取消激活oncl​​ick功能?

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Untitled Document</title>
        <style type="text/css">
            <!--
            body,td,th {
            font-size: 12px;
            }
            div {
            border:1px solid #444444;
            background-color:#AAAAAA;
            padding:10px;
            margin:10px;
            }
            -->
        </style>
        <script id="ubo_js" language="JavaScript" type="text/javascript">
            $(document).ready(function art()
            {    


            /* IF STATUS == 0 .. abbort the onclick function by mouseup */

            });
        </script>

    </head>

    <body>

        <input id="status" type="text" value="1">
        <br /><br />

        <a href="#" onclick="$('#status').val('0');">switch to 0</a>
        | <a href="#" onclick="$('#status').val('1');">switch to 1</a>

        <br /><br />

        <div class="drot" onclick="alert('hello');">click here</div>



    </body>
</html>

- &GT;工作实例 http://www.jsfiddle.net/V9Euk/43/

亲切的问候 彼得

2 个答案:

答案 0 :(得分:1)

您可以为HTML元素指定一个ID

<a href="#" onclick="$('#status').val('0');" id="element1">

然后只需解决它并删除onclick函数

var e1 = document.getElementById("element");
e1.onclick = function() {
    alert("leave me alone!");
}

如果click事件直接调用该方法,则根本不需要ID,但您甚至可以使用它:

function val() {
    // Do the other stuff on click
    this.onclick = function() {
       // I will do nothing at all
    }
}

答案 1 :(得分:0)

是的,有可能;)。撇开舌头,你是说你想要:

只需在点击功能中添加if语句即可。