输入类型文件未正确将图像放入图像标签

input type file not properly putting image into image tag

本文关键字:图像 标签 类型 文件 输入      更新时间:2023-09-26

我正在做一些事情,这个问题得到了回答,但我需要不同的用途。我对它的工作原理有一个jsFidd。 http://jsfiddle.net/TbZzH/4/

这很好,但是当我在我的代码中这样做时,它会告诉我data.files[0]不起作用,并且被称为未定义。 它也不能识别 FileReader() 对象。

我的代码如下,以jsFiddle为例。

$(function(){
  $("input[type='file'].attribute").on("change", function () { updateDesigner(this); });
});
function updateDesigner(input){
  var t = input;
  if ($(input).attr("type") == 'file'){
    try{
      var data = $(t)[0];
      var file = data.files[0];   //<------   FAILS HERE.  .files is an undefined attr.
      var reader = new FileReader();   //<--- working around it, doesnt understand this object as well
      reader.onload = function (e) {
          value = e.target.result;
      }
      reader.readAsDataURL(file);
    }catch(errrrr){
      alert("error putting image into image tag: "+errrrr.toString());
    }
  }
  srcFunction(value); //takes the value and applied it to the src attr of the image tag.
}

我想将数据转换为值,一切都会顺利进行,但我不确定发生了什么。

虽然IE使用了一些示例,但这里的问题似乎与网站的"信任"和"安全性"有关。

要使静态图像出现在计算机屏幕上,我需要使其成为受信任的站点,并将图像重新路由到HTTPS