注册事件 js
- <script type="text/javascript">
- function AttachEvent(target, eventName, handler, argsObject)
- {
- var eventHandler = handler;
- if(argsObject)
- {
- eventHander = function(e)
- {
- handler.call(argsObject, e);
- }
- }
- if(window.attachEvent)//IE
- target.attachEvent("on" + eventName, eventHander );
- else//FF
- target.addEventListener(eventName, eventHander, false);
- }
- function LinkClick(e)
- {
- alert(this.name);
- // var target = e.srcElement || e.target;
- // alert(target.getAttribute(‘aaa‘));
- }
- function addEvent()
- {
- var obj = new Object();
- obj.name = "link1111";
- var link1 = document.getElementById("link1");
- AttachEvent(link1, "click", LinkClick, obj);
- obj = new Object();
- obj.name = "link2222";
- var link2 = document.getElementById("link2");
- AttachEvent(link2, "click", LinkClick, obj);
- }
- </script>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。