上传图片后,怎么让它作为一个背景图片显示出来

比如

 <div id="title">1243234</div>

上传完成后,我要让刚上传的图片作为title的背景图片

  <div id="title" style="background:url(图片的url地址)">1243234</div>

这个得写css里#title{background:url(图片路径) no-repeat;}

在css里使用背景属性 background

    background:url(图片路径);
background-repeat: no-repeat;
background-position: center;
background-size: cover;
background-attachment: fixed;
    你这么写试试。

你是想说点击上传,选择一个文件让他变成背景图片么?
//图片上传预览 IE是用了滤镜。
function previewImage(file)
{
var MAXWIDTH = 120;
var MAXHEIGHT = 120;
var div = document.getElementById('preview');//这边需要修改
if (file.files && file.files[0])
{
div.innerHTML ='';
var img = document.getElementById('imghead');
img.onload = function(){
var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
img.width = rect.width;
img.height = rect.height;
// img.style.marginLeft = rect.left+'px';
img.style.marginTop = rect.top+'px';
}
var reader = new FileReader();
reader.onload = function(evt){img.src = evt.target.result;}
reader.readAsDataURL(file.files[0]);
}
else //兼容IE
{
var sFilter='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
file.select();
var src = document.selection.createRange().text;
div.innerHTML = '';
var img = document.getElementById('imghead');
img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
status =('rect:'+rect.top+','+rect.left+','+rect.width+','+rect.height);
div.innerHTML = "

";
}
}
function clacImgZoomParam( maxWidth, maxHeight, width, height ){
var param = {top:0, left:0, width:width, height:height};
if( width>maxWidth || height>maxHeight )
{
rateWidth = width / maxWidth;
rateHeight = height / maxHeight;
        if( rateWidth > rateHeight )
        {
            param.width =  maxWidth;
            param.height = Math.round(height / rateWidth);
        }else
        {
            param.width = Math.round(width / rateHeight);
            param.height = maxHeight;
        }
    }

    param.left = Math.round((maxWidth - param.width) / 2);
    param.top = Math.round((maxHeight - param.height) / 2);
    return param;
}