Javascript 无需单击的第一个图像
我的图像库有问题。当我点击一个缩略图时,它会工作,并且会显示一个大图像,但我希望在不点击缩略图的情况下显示第一个图像。 我怎样才能解决这个问题? 下面是我的代码 这是我的Django模板:Javascript 无需单击的第一个图像,javascript,jquery,python,django,templates,Javascript,Jquery,Python,Django,Templates,我的图像库有问题。当我点击一个缩略图时,它会工作,并且会显示一个大图像,但我希望在不点击缩略图的情况下显示第一个图像。 我怎样才能解决这个问题? 下面是我的代码 这是我的Django模板: <div class="row"> {% if offer_images1 %} <div class="col-md-6 col-sm-6 col-xs-12" id="help"> {% for image in offer_imag
<div class="row">
{% if offer_images1 %}
<div class="col-md-6 col-sm-6 col-xs-12" id="help">
{% for image in offer_images1 %}
<img id="imageHere" class="zoom_01 img-responsive" data-zoom-image="{{ image.paint.url }}" />
{% endfor %}
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<i><b>{% trans "Title" %}: </b>{{ offer_gallery.title }}</i><br>
<i><b>{% trans "Status" %}: </b>{{ offer_gallery.status }}</i><br>
</div>
{% for image in offer_images1 %}
<div class="col-md-3 hover08 column">
<div style="padding-top:20px;padding-bottom:20px;">
<figure class="img1">
<img class="thumb img-responsive" src="{{ image.paint.url }}" width="150" height="150" style="border:1px solid grey">
</figure>
</div>
</div>
{% if forloop.counter|divisibleby:"4" and not forloop.last %}
</div><div class="row">
{% endif %}
{% endfor %}
{% endif %}
</div>
{%if offer_images1%}
{提供中图像的百分比\u images1%}
{%if-forloop.counter |可除数为:“4”而非forloop.last%}
{%endif%}
{%endfor%}
{%endif%}
以下是我的jQuery代码:
<script>
$(document).ready(function () {
$( ".thumb" ).each(function(index) {
$(this).on("click", function(){
var image = $(this).attr("src")
$("#imageHere").attr('src', image);
});
});
});
</script>
$(文档).ready(函数(){
$(“.thumb”)。每个(函数(索引){
$(此)。在(“单击”,函数()上){
var image=$(this.attr(“src”)
$(“#imageHere”).attr('src',image);
});
});
});
触发单击第一张图像上的事件
<script>
$(document).ready(function () {
$(".thumb").on("click", function(){
$("#imageHere").attr('src', $(this).attr("src"));
});
// ======= HERE =======
$( ".thumb:first" ).click();
});
</script>
$(文档).ready(函数(){
$(“.thumb”)。在(“单击”,函数(){
$(“#imageHere”).attr('src',$(this.attr(“src”));
});
//=========这里=======
$(“.thumb:first”)。单击();
});
甚至更简单<代码>})。等式(0)。单击()代码>@RokoC.Buljan(+1)。我喜欢一个内衬:“马克,考虑选择答案来结束你的问题。”UZBEKJON,我看到你正在期待一个漂亮的绿色支票,所以,同样的方式,我提醒你,OPS可以使用一些rep甚至更多(有用的赏金等),所以如果你发现Q格式良好,你可以显示一些运动技巧第一!!)