0

有没有办法激活一个 onclick 事件,比如

onClick="variable();size()"

哪里还有onmousedown事件?

class="div_1" onClick="variable();size()" onmousedown="clickin(this)" 

onmousedown javascript 会在哪里激活 onclick javascript?

function clickin(control) {
    var allElements = document.getElementById(control.id);
    for (var i=0; i<allElements.length; i++) { 
        eval(document.getElementById('elementId').getAttribute('onclick'));
    }
}
4

1 回答 1

0

onclick属性通常会变成一个函数。所以这将起作用:

<a onclick="alert('click');" onmousedown="this.onclick()">Click here to click</a>

/编辑:

<a id="a_target">Click here to click</a>
<script type="text/javascript">
     var a_target = document.getElementById('a_target');

     a_target.onclick = function(){ alert('click'); };   // CODE TO ADD ONCLICK
     a_target.onmousedown = function(){ this.onclick();  } // CODE TO ADD MOUSEDOWN

     // TO REMOVE THEM DO THIS
     a_target.onclick = a_target.onmousedown = function(){} // NO MORE CLICKS
     a_target.onmousedown = function(){
          alert('mousedown!'); // DISPLAYS POPUP
          a_target.onmousedown = function(){} // STOPS FROM CLICK
          a_target.onclick = function(){ alert('CLICK :D'); } // WILL POPUP CLICK NOW AND ON NEXT CLICK
     }

     // TO POPUP CLICK ONLY ON NEXT CLICK CHANGE ONMOUSEDOWN TO ONMOUSEUP
</script>
于 2012-06-01T03:45:58.950 回答