有没有办法激活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'));
}
}发布于 2012-06-01 11:45:59
onclick属性通常会转换为一个函数。所以这将会起作用:
<a onclick="alert('click');" onmousedown="this.onclick()">Click here to click</a>/Edit:
<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>https://stackoverflow.com/questions/10844089
复制相似问题