我在iframe中得到一个未定义的错误

我在下面有一个iframe:

 

我试图在下面停止命令,但我一直收到一个未定义的错误:

 $('.upload_target').contentwindow is undefined 

如何修复此未定义的错误?

以下是代码:

  $(".uploadbutton").click(function() { $(".upload_target").contentWindow.stop(); //for anything but IE $(".upload_target").contentWindow.document.execCommand("Stop"); // for IE return stopImageUpload(); 

});

你得到undefined因为contentWindow是本机Javascript,你在jQuery集合上使用它,它没有contentWindow作为值。 您必须首先获取原始DOM对象。 改为:

 $('.upload_target').get(0).contentWindow