<html>
<head>
</head>
<body>
<script type="text/javascript">
function go(e){
e=e||window.event;
if(e.keyCode==13){
var btn =document.getElementById('link');
if( document.createEvent ) {
var evObj = document.createEvent('MouseEvents');
evObj.initEvent( 'click', true, false );
btn.dispatchEvent(evObj);
}
else if( document.createEventObject ){
btn.fireEvent('click');
}
}
}
</script>
<input type="text" id="text" οnkeydοwn="go()" />
<button id="btn" οnclick="alert('click')">按钮</button>
<a href="http://www.baidu.com" id="link">这是个链接</a>
</body>
</html>
原生js事件创建及触发
最新推荐文章于 2023-06-27 21:16:48 发布