有没有办法激活像
这样的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'));
}
}
答案 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>