日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

onload事件_图像onLoad事件+ Internet ExplorerJavaScript问题

發布時間:2023/12/31 javascript 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 onload事件_图像onLoad事件+ Internet ExplorerJavaScript问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

onload事件

I was recently coding an application that would inject an image into the page and then execute a given function when the image's onLoad event fires. My code was working everywhere except Internet Explorer. That wasn't all together shocking initially but the fact that even IE8 was failing to the fire the onLoad event was discouraging. Here's what my code looked like:

我最近正在編寫一個應用程序,該應用程序將圖像插入頁面,然后在圖像的onLoad事件觸發時執行給定的功能。 我的代碼在Internet Explorer 以外的所有地方都可以使用 。 最初這并沒有使所有人震驚,但是即使IE8也無法觸發onLoad事件,這一事實令人沮喪。 這是我的代碼:

var img = new Element('img',{alt: this.title ? this.title.get('html') : this.options.url,src: this.options.url,events: {error: function() {this.messageBox.set('html',this.options.errorMessage);img.dispose();}.bind(this),load: function() {img.setStyle('display','');this.unfade();if(!this.footer) {img.setStyle('cursor','pointer').addEvent('click',this.close.bind(this));}}.bind(this)},styles: {display: 'none'} }).inject(this.messageBox);

On a hunch I detached the "src" assignment and coded that as a separate statement:

憑直覺,我分??離了“ src”賦值并將其編碼為單獨的語句:

var img = new Element('img',{alt: this.title ? this.title.get('html') : this.options.url,events: {error: function() {this.messageBox.set('html',this.options.errorMessage);img.dispose();}.bind(this),load: function() {img.setStyle('display','');this.unfade();if(!this.footer) {img.setStyle('cursor','pointer').addEvent('click',this.close.bind(this));}}.bind(this)},styles: {display: 'none'} }); img.set('src',this.options.url).inject(this.messageBox); //for ie

Not too surprisingly that worked. The reason my modification worked is that image was being pulled from cache as soon as the SRC attribute was set, thus "beating" the event assignment to the punch. Keep this in mind if you run into onLoad issues with your images.

這樣做并不奇怪。 我的修改起作用的原因是,一旦設置了SRC屬性,就會從緩存中拉出圖像,從而將事件分配“打”到打Kong器。 如果圖像遇到onLoad問題,請記住這一點。

翻譯自: https://davidwalsh.name/image-load-event

onload事件

總結

以上是生活随笔為你收集整理的onload事件_图像onLoad事件+ Internet ExplorerJavaScript问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。