星期六, 8月 04, 2012

[jQuery] $.ajax 讀取影像

似乎不需要弄$.ajax也可以達到這個需求XD

var img = $("#imgElem").attr('src', 'http://somedomain.com/image.jpg')
                      .load(function() {
                         if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
                             alert('broken image!');
                         } else {
                             $("#something").append(img);
                         }
                      });

Reference:

沒有留言:

張貼留言

留個話吧:)

其他你感興趣的文章

Related Posts with Thumbnails