があるされていると確信していますドキュメントオブジェクトに追加します。代わりに結合
使用通常のイベント:
$('img').on("error", function() {
this.src = ResolveUrl("~/images/tree-item.png");
});
- P.S - これは、このコマンドが実行されたときにDOM上に既にある画像にのみ機能します。
だけでなく、動的に追加の画像を処理するために、あなたがDOMに追加したすべての画像に、このイベントを添付する必要があります。ここでは例です:
function handleError() {
this.src = ResolveUrl("~/images/tree-item.png");
}
// Bind the event to the existing images on the DOM when the document is ready
$(document).ready(function() {
$('img').on("error", handleError);
}
// An example for a function that adds images dynamically
function addImage(imgSource, destination) {
var newImg = $("img").attr("src", imgSource)
.on("error", handleError);
$(destination).append(newImg);
}
ResolveUrl()コードはどこですか? – Unknown
クライアント側の機能です。警告がトリガーされていなくても削除します – user960567
'error'イベントを使って' document'に対してイベント委譲を行うことができるかどうかは確かではありません。私が間違っていない場合、このイベントはドキュメントオブジェクトにバブルしません。 – Itay