input type file not properly putting image into im

2019-09-12 16:20发布

I was working on something and the question was answered, but i need a different use for it. I have a jsFiddle of how it works. http://jsfiddle.net/TbZzH/4/

that is fine and dandy, but when i do it in my code, it will tell me that data.files[0] does not work, and is said to be undefined. It also does not recognize the FileReader() object.

My code is as follows, using jsFiddle as an example I worked from.

$(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.
}

I want to pipe the data into value and everything would run smooth, but i am not sure what is going on.

1条回答
Bombasti
2楼-- · 2019-09-12 17:14

While IE works with some examples, The issues here seem to be related to the websites "trust" and "secureness"

to get a static image to appear on the computer screen, i need to make it a trusted site as well as having the rerouted to https

查看更多
登录 后发表回答