JQuery: how to disable image click function during loading?

This will not work using:

$('div#menuBar,#goLeftBtn,#goRightBtn').attr('disabled', true);

in document.ready

Any ideas? Thank!

EDIT:
My html is basically like this:

  <div id="floatRight">
       <img src="./images/all_left.png" id="goAllLeft" class="arrow" />
       <img src="./images/left.png" id="goLeft" class="arrow" />
       <img src="./images/right.png" id="goRight" class="arrow"/>
       <img src="./images/all_right.png" id="goAllRight" class="arrow" />
    </div>

I know that these are not the exact names of the images in the jquery code above, but here is how all my IMGs are basically configured and for this particular line of code I only need those img that will be disabled.

+3
source share
4 answers
$('div#menuBar,#goLeftBtn,#goRightBtn').click(function() { return false; });

will work until you are ready to activate it.

Or in fact, why don't you just attach the click event before loading it?

+1
source

, , ?

, .

<img id="menuBar" />
<img id="goLeftBtn" />
<img id="goRightBtn" />

,

<script type="text/javascript">
    $(function(){
        $("#goLeftBtn").click(function() { /* go left */ });
        $("#goRightBtn").click(function() { /* go right */ });
        $("#menuBar").click(function() { /* go menu? */ });
    });
</script>

, e.preventDefault, , , jQuery .


click inline ( , ):

<img id="menuBar" onclick="return DoMenuStuff();" />
<img id="goLeftBtn" onclick="return GoLeft();" />
<img id="goRightBtn" onclick="return GoRight();" />

- :

<script type="text/javascript">
    var loaded = false;
    $(function(){
        loaded = true; // page done loading
    });

    function DoMenuStuff()
    {
        if(loaded) { /* do stuff */ }
    }

    function GoLeft()
    {
        if(loaded) { /* do stuff */ }
    }

    function GoRight()
    {
        if(loaded) { /* do stuff */ }
    }
</script>
+3

, , disabled #menuBar, #goLeftBtn #goRightBtn.
, cancle event handler, <img> "disabled".

, / . , click. jQuery, .unbind().

inline event handler, , .

+1

<div> , , , z. . "load" "" <div> ( "display: none" ).

0

Source: https://habr.com/ru/post/1762659/


All Articles