4

我在下面有一个 iframe:

<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></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();

});

4

1 回答 1

7

你得到undefined是因为contentWindow它是原生 Javascript 并且你在一个 jQuery 集合上使用它,它没有contentWindow作为一个值。您必须首先获取原始 DOM 对象。改为这样做:

$('.upload_target').get(0).contentWindow
于 2012-04-16T00:49:54.817 回答