在点击时显示多个图像而不是一次显示一个

时间:2016-12-26 12:38:29

标签: javascript jquery html image

每次尝试更改图像时,我都无法使用此图像多个图像出现倍增我希望能够一次显示一个图像,如果我想我可以单击图像以便图像再次出现基本上。我也想在每个图像上使用可拖动和可调整大小

$(document).ready(function() {
  $('#imajes').change(function() {
    $('.subselector').hide();
    $('.smallimages').hide();
    $('#' + $(this).val()).show();
  });
  $('.subselector').on('change', function() {
    $('.smallimages').hide();
    var id = $(this).attr('id');
    var val = $(this).val();
	
 $('#dog').on('change', function() {
  $("#lrgdogimges").css('display', (this.value == 'smalldog') ? 'block' : 'none');
});

 $('#dog').on('change', function() {
  $("#smdogimges").css('display', (this.value == 'largedog') ? 'block' : 'none');
});
  
 

  $('img').on('click', function() {
    var src = $(this).attr('src');
    $('#fotos').append('<img class="modal-content" src="' + src + '">');
});
});
});
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>

<div id="fotos" ><img class="modal-content" id="imgdisplay" /></div>


<select id="imajes">
  <option value="">Choose Image</option>
  <option value="dog">dog</option>
  <option value="cat">cat</option>
</select>


<select id="dog" name="subselector" class="subselector" style="display:none">
  <option value="">Choose an item</option>
  <option value="smalldog">small dog</option>
  <option value="largedog">Large Dog</option>
</select>


<select id="cat" name="subselector" class="subselector" style="display:none">
  <option value="">Choose an item</option>
  <option value="smallcat">small cat</option>
</select>

  
<div style='display:none;' id="lrgdogimges" class="smallimages">
  <div data-image="http://i.imgur.com/iXHPRVf.jpg">
    <img src="http://i.imgur.com/iXHPRVf.jpg" alt="Smiley face" width="55" height="55">
  </div>
  <div data-image="https://torcdesign.com/shirts/lyellow.jpg">
    <img src="https://torcdesign.com/shirts/lyellow.jpg" alt="Smiley face" width="55" height="55">
  </div>
</div>
<div style='display:none;' id="smdogimges" class="smallimages">
  <div data-image="https://torcdesign.com/shirts/wlsblack.jpg">
    <img src="https://torcdesign.com/shirts/wlsblack.jpg" alt="Smiley face" width="55" height="55">
  </div>
  <div data-image="http://i.imgur.com/iXHPRVf.jpg">
    <img src="http://i.imgur.com/iXHPRVf.jpg" alt="Smiley face" width="55" height="55">
  </div>
  
</div>

<div style='display:none;' id="catimges" class="smallimages">
  <div data-image="http://i.imgur.com/BHoIzPj.jpg">
    <img src="http://i.imgur.com/BHoIzPj.jpg" alt="Smiley face" width="55" height="55">
  </div>
</div>

只需将一次点击显示的图片更改为每次点击一次

2 个答案:

答案 0 :(得分:1)

据我了解,您希望在#fotos容器内一次只显示一张照片。为此,只需将.append()函数更改为.html(),如:

$('img').on('click', function() {
    var src = $(this).attr('src');
    $('#fotos').html('<img class="modal-content" src="' + src + '">');
});

这将替换img内的#fotos,而不是插入另一个。{/ p>

答案 1 :(得分:1)

您似乎做了如下不正确的事情,

$trigger = New-JobTrigger -AtStartup -RandomDelay 00:00:45
$pwd= ConvertTo-SecureString “{your-vm-adminPwd}” -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential (“{your-vm-adminName}”, $pwd)
Register-ScheduledJob -Trigger $trigger -FilePath $installDir\start1.ps1 -Name bruceScheduledJob -Credential $credential -Authentication CredSSP

您应该只绑定一次事件。

$('#dog').on('change', function() {
  $("#lrgdogimges").css('display', (this.value == 'smalldog') ? 'block' : 'none');
});

 $('#dog').on('change', function() {
  $("#smdogimges").css('display', (this.value == 'largedog') ? 'block' : 'none');
});

请按照$('#dog').on('change', function() { $("#lrgdogimges").css('display', (this.value == 'smalldog') ? 'block' : 'none'); $("#smdogimges").css('display', (this.value == 'largedog') ? 'block' : 'none'); }); 方法的代码移动您。它是多次绑定$('.subselector').on('change', function() { 事件因此问题。

click