-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_show_update_remove_by_jquery.py
55 lines (48 loc) · 1.75 KB
/
image_show_update_remove_by_jquery.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<div class="row">
<div>
<label for="image" class="control-label">profile Image</label>
<input type="file" name="profile_image" class="form-control" id="imgInp"
accept=".jpeg,.png,.jpg,.gif,.svg">
{% if profile.image %}
<p>
<img style="border-radius: 50%;" id="tag_hide"
src="/{{ profile.image.url }}" alt="profile Image"
height="80px" width="80px"/>
<span style=" cursor: pointer;" class="close">×</span>
</p>
{% endif %}
<img style="border-radius: 50%;visibility: hidden;" id="blah" src=""
alt="profile Image"
height="80px" width="80px"/>
<p></p>
<input type="hidden" name="checkimage" id="checkimage" value="{% if profile.image %}{{ profile.image }}{% else %}{% endif %}">
</div>
</div>
<script>
var closebtns = document.getElementsByClassName("close");
var i;
for (i = 0; i < closebtns.length; i++) {
closebtns[i].addEventListener("click", function () {
this.parentElement.style.display = 'none';
document.getElementById("checkimage").value = "";
});
}
</script>
<script>
document.getElementById("imgInp").onclick = function () {
document.getElementById("blah").style.visibility = "visible";
$("#tag_hide").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 () {
readURL(this);
});
</script>