//如何在代码中触发事件
<a href="#" οnclick="alert('onclick executed');" id="testLink">some link</a>
<script type="text/javascript">
<!--
function fireEvent(element, eventName) {
evt = document.getElementById(element)[eventName];
if (typeof(evt) == "function") {
document.getElementById(element)[eventName]();
return true;
} else {
console.log('failed to trigger this event.');
return false;
}
}
fireEvent("testLink", "onclick");
-->
</script>