【问题标题】:Display image one by one一张一张显示图片
【发布时间】:2021-12-14 03:30:33
【问题描述】:

我的表单中有一个复选框,当项目被选中时会显示图像。

是否有可能每次点击一个项目时图像都会一个一个地显示,因为目前,每次我在复选框上选中一个项目时,它都会显示在我分配的 div 上。

我想要实现的是,当一个项目被选中时,它会显示出来,当我点击另一个项目时,以前的图像将被选中的新项目覆盖。

我在图像中分配了一个 ID 和类,这是我的 JS:

jQuery(document).ready(function( $ ){
  
$(function() {
  $('.decalcheckbox input[type=checkbox]').on("change",function() { 
    var checkbox = $(this).val().toLowerCase();
    var checkboxremovespace = checkbox.replace(/ /g, "_")
$('#decal_'+ checkboxremovespace).toggle(this.checked); 
  }).change(
  ); // trigger the change
});

}); 

对不起我的英语,但我希望我能解释我想说的话。

谢谢。

【问题讨论】:

    标签: image checkbox display


    【解决方案1】:

    我只是对我的代码做了一些修改,如下所示。

    希望有人能解释一下。

    jQuery(document).ready(function( $ ){
      
    $(function() {
      $('.decalcheckbox input[type=checkbox]').on("change",function() { 
        if ($(this).is(':checked')) {
          $("#bento_preview_item").hide();
        }
        else{
          $("#bento_preview_item").show();
        }
        var checkbox = $(this).val().toLowerCase();
        var checkboxremovespace = checkbox.replace(/ /g, "_")
    $('#decal_'+ checkboxremovespace).toggle(this.checked); 
      }).change(
      ); // trigger the change
    });
    
    });
    

    谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-19
      • 2022-10-21
      相关资源
      最近更新 更多