网站地图    收藏   

主页 > 前端 > javascript >

javascript获取input表单的值并显示在页面的实现方法

来源:未知    时间:2018-03-11 21:55 作者:小飞侠 阅读:

[导读] javascript获取input表单的值并显示在页面的实现方法 代码如下: $(document).on(change,.photo-box.file,function(){//alert($(this).val());functiongetObjectURL(file){varurl=null;if(window.createObjectURL!=undefined){//basicu...

javascript获取input表单的值并显示在页面的实现方法

代码如下:

$(document).on('change', '.photo-box .file', function () {
  //alert($(this).val());
  function getObjectURL(file) {
    var url = null;
    if (window.createObjectURL != undefined) { // basic
      url = window.createObjectURL(file);
    } else if (window.URL != undefined) { // mozilla(firefox)
      url = window.URL.createObjectURL(file);
    } else if (window.webkitURL != undefined) { // webkit or chrome
      url = window.webkitURL.createObjectURL(file);
    }
    return url;
  }
  var objUrl = getObjectURL(this.files[0]);
  console.log("objUrl = " + objUrl);
  var html = '<div class="photo-box"><img src="' + objUrl + '" alt=""><div class="photo-btn"><p>删除</p></div></div>';
  $(this).parent().parent().append(html);
})


自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论