由onmousedown激活的onclick

时间:2012-06-01 03:38:53

标签: php javascript html var

有没有办法激活像

这样的onclick事件
onClick="variable();size()"

哪里还有一个onmousedown活动?

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

onmousedown javascript会激活oncl​​ick javascript吗?

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

1 个答案:

答案 0 :(得分: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>