Kir*_*kov 2 html javascript jquery
这是我需要做的.所以我有这个代码
<input type="file" id="uploadImage" name="image" />
<input type="submit" id="ImageName" name="submit" value="Submit">
Run Code Online (Sandbox Code Playgroud)
因此,当我单击"选择..."按钮浏览图像时,我希望将该图像的路径保存在变量中.
或者基本上我需要做的是使这条路径成为图像的src.
$('#Imageholder').append('<img src="" class="ImgCoords" >');
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
对不起,如果说明不好:
这是我做的一个例子,根据您的需要进行调整:
我添加了一个按钮删除上传的文件,如果你不喜欢显示/隐藏效果只是删除slow,图像只显示在上传:
$('#blah').hide();
$('#remove').hide();
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
if( $('#imgInp').val()!=""){
$('#remove').show();
$('#blah').show('slow');
}
else{ $('#remove').hide();$('#blah').hide('slow');}
readURL(this);
});
$('#remove').click(function(){
$('#imgInp').val('');
$(this).hide();
$('#blah').hide('slow');
$('#blah').attr('src','http://upload.wikimedia.org/wikipedia/commons/thumb/4/40/No_pub.svg/150px-No_pub.svg.png');
});
Run Code Online (Sandbox Code Playgroud)
HTML代码:
<form id="form1">
<input type='file' id="imgInp" name='image'/>
<img id="blah" src="#" alt="your image" />
</form>
Run Code Online (Sandbox Code Playgroud)