日期:2014-05-16  浏览次数:20481 次

同步图片的src和input的
现在
<img id="ipc" src="" />

<input name="showpic" id="showpic" class="border" type="text" size="40" value="" readonly="readonly"  />

<input type="button" id="image" value="上传图片" class="sub_btn" />

<input type="button" id="image" value="查看图片" class="sub_btn" onkeyup="document.getElementById('ipc').src=document.getElementById('showpic').value" onblur="document.getElementById('ipc').src=document.getElementById('showpic').value" />

这样很麻烦啊  能不能 input和img同时获得值? 不用再点查看图片了~~
------解决方案--------------------
<img src="" alt="" id="ipc">
<input name="showpic" onchange="view(this)" type="text" size="40" value="" readonly="readonly"  />
<script type="text/javascript">
function view(obj){
    var src="";
    if(document.all){
        obj.select();
        src = document.selection.createRange().text;
        document.selection.empty();
        if(/\.(gif
------解决方案--------------------
jpg
------解决方案--------------------
jpeg
------解决方案--------------------
png
------解决方案--------------------
bmp)/i.test(src)){
            document.getElementById("ipc").src=src;
        }else{
            alert("请选择图片!");
        }
    }else{
        var file=obj.files[0];        src=window.createObjectURL&&window.createObjectURL(file)
------解决方案--------------------
window.URL&&window.URL.createObjectURL(file)
------解决方案--------------------
window.webkitURL && window.webkitURL.createObjectURL(file);
        document.getElementById("ipc").src=src;
    }
}
</script>