attachevent

addEventListener Code Snippet Translation and Usage for cross-browser detectioin

浪尽此生 提交于 2020-01-17 04:43:26
问题 I've come across a piece of code that I'd like to model. However, I just have a few questions and perhaps you guys can help. Here's the code: function addEvent( brw_obj, type, func ) { if (brw_obj.addEventListener) { // all browsers except IE < v9 brw_obj.addEventListener( type, func, false ); } else if (brw_obj.attachEvent) { // IE only for v < v9 brw_obj["e"+type+func] = func; brw_obj[type+func] = function() { brw_obj["e"+type+func]( window.event ); } brw_obj.attachEvent( "on"+type, brw_obj

attachEvent 与addEventListener到底有什么区别呢?

只愿长相守 提交于 2020-01-08 12:14:23
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> attachEvent 与addEventListener到底有什么区别呢? 总结如下: 一、适应的浏览器版本不同 attachEvent方法适用于IE addEventListener方法适用于FF 二、针对的事件不同 attachEvent中的事件带on 而addEventListener中的事件不带on 三、参数的个数不同 attachEvent方法两个参数:第一个参数为事件名称,第二个参数为接收事件处理的函数; addEventListener 有三个参数:第一个参数表示事件名称(不含 on,如 "click");第二个参数表示要接收事件处理的函数;第三个参数是一个bool值,一般为false 第三个参数叫做useCapture,是一个boolean值,就是true or false,如果送出true的话就是瀏览器会使用Capture方式,false的话是Bubbling,只有在特定状况下才会有影响,通常建议是false,而会有影响的情形是目标元素(target element)有祖先元素(ancestor element),而且也有同样的事件对应函数,我想,看图会比较清楚。 像这张图所显示的,我的范例有两层div元素,而且都设定有click事件,一般来说

IE attachEvent call returns true, but handler shows “null”

会有一股神秘感。 提交于 2019-12-24 14:09:34
问题 I have a fairly simple ASP.NET page that renders an HTML input (text box). Within the generated HTML, I attach a handler to several events, including onfocus, onkeypress, and onkeyup. Because this is a solution targeted at a version of IE that does not support addEventListener (situation about which I can do nothing), I am forced to use attachEvent. A typical call to attachEvent is as follows - I've excerpted this source from the original for the sake of brevity/clarity, so it is not

this.style.backgroundColor don't work in IE7/8

别来无恙 提交于 2019-12-23 04:45:55
问题 my code is: <!DOCTYPE html> <html> <head> <title>Demo</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> p{ border:1px solid #CCC; margin:5px; padding:5px; } </style> <script type="text/javascript"> window.onload = changeColor; function changeColor() { for(var i =0; i < document.getElementById("main").getElementsByTagName("p").length; i++) { var obj = document.getElementById("main").getElementsByTagName("p")[i]; if (window.addEventListener) {

Scope troubles in Javascript when passing an anonymous function to a named function with a local variable

夙愿已清 提交于 2019-12-20 01:35:21
问题 Sorry about the title - I couldn't figure out a way to phrase it. Here's the scenario: I have a function that builds a element: buildSelect(id,cbFunc,...) Inside buildSelect it does this: select.attachEvent('onchange',cbFunc); I also have an array that goes: var xs = ['x1','x2','x3'...]; Given all of these, I have some code that does this: for(var i = 0; i < xs.length; i++) { buildSelect(blah,function(){ CallBack(xs[i],...) },...); } The issue is that when onchange gets fired on one of those

Cross-browser event handling

眉间皱痕 提交于 2019-12-12 13:36:49
问题 I need a cross-browser function for registering event handlers and a (mostly) consistent handler experience. I don't need the full weight or functionality of a library such as jQuery, so I've written my own. I believe I've accomplished my goals with the code below, and so far my testing has been successful, but I've been staring at it for too long. Are there any flaws in my logic or gotchas that I'm missing? EDIT 1: Commented each block with browser intent for clarity. Updated IE block to not

addEventListener duplicating Select Options Javascript

放肆的年华 提交于 2019-12-12 02:35:09
问题 I created a javascript function to copy data from an input on another jQuery tab to a Summary tab. I am having an issue with duplication with a dropdown. I need for it to replace the exisiting information when choosing another selection if a change is needed. HTML - Dropdown <select id="accountCoordinator1" class="txtbxList"> <option>Select</option> <option>Jon</option> <option>Lori</option> </select> HTML - Placement <table> <tr> <td id="summaryAccountCoordinator1"></td> </tr> </table>

Addeventlistener fallback for older IE

天大地大妈咪最大 提交于 2019-12-11 07:58:46
问题 I am trying to create a simple fallback function, which will make sure addeventlistener will work in IE versions older than 9. So far i have this if (!Element.prototype.addEventListener) { Element.prototype.addEventListener = function(ev, fc) { xxx.attachEvent('on' + ev, fc); } } The problem is, that I don't know how to get the reference to the element to which the event is being attached to. (the xxx) Any advice is appreciated. 回答1: That's​​​​​​​​​​​​​​​​​ this . 来源: https://stackoverflow

Get the caller of the event from attachEvent

会有一股神秘感。 提交于 2019-12-08 05:19:12
问题 I am trying to do something simple: I have a bunch of Images which are being load through JS. I attach an event listener to the load event, and after the Image is being loaded, in the listener function I would like to get the calling Image and retrieve properties from it. Here is my code, simplified: function loadImages() { for (var i = 0; i < arrDownloadQueueBasic.length; i++) { var path = arrDownloadQueueBasic[i].path; var img = new Image(); img.type = arrDownloadQueueBasic[i].type; img

Get the caller of the event from attachEvent

China☆狼群 提交于 2019-12-07 01:42:29
I am trying to do something simple: I have a bunch of Images which are being load through JS. I attach an event listener to the load event, and after the Image is being loaded, in the listener function I would like to get the calling Image and retrieve properties from it. Here is my code, simplified: function loadImages() { for (var i = 0; i < arrDownloadQueueBasic.length; i++) { var path = arrDownloadQueueBasic[i].path; var img = new Image(); img.type = arrDownloadQueueBasic[i].type; img.attachEvent(img, 'load', setBasicElement); img.src = path; } } function setBasicElement(e) { var caller =