Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
画像が正しく読み込まれるかどうかを確認する方法を知っている人はいますか。画像をプリロードするスクリプトがあります。画像が存在しない場合、スクリプトが終了しないので、属性「src」をデフォルト値にします。
image.load(function(){ //it never reache here if the image doesn't exist }).attr('src','a non existing image');
ありがとう
var image = $('<img>').appendTo('body'); image.load(function() { // image is found and loaded }).error(function() { // image not loaded image.attr('src','default-image.jpg'); }).attr('src','a non existing image');