首页 \ 问答 \ 按钮onclick时按字母顺序堆叠图像(images in alphabetical order are stacked when button onclick)

按钮onclick时按字母顺序堆叠图像(images in alphabetical order are stacked when button onclick)

功能:

当用户进入主菜单页面时,图像项目集已经按字母顺序排列和显示。 然后,用户可以选择不同的类别按钮,按钮A将返回具有相同排序字母顺序的一组图像,而按钮B将返回具有相同排序字母顺序的另一组图像。

我做了什么

我有3组图像源数组:

1.)所有图像源2.)ButtonA类别图像源3.)ButtonB类别图像源

我已从阵列中获取所有图像(所有图像源),并插入特定位置说: <div class="Container"><div id= "list" class="innerScroll"></div></div> 。 然后根据字母顺序显示图像。

这是您的细读代码。

var BrandNameArray = ['http://lorempizza.com/380/240',
  'http://dummyimage.com/250/ffffff/000000',
  'http://lorempixel.com/g/400/200/',
  'http://lorempixel.com/g/400/200/sports/'
];

var CategoryA = ['http://lorempizza.com/380/240',
  'http://dummyimage.com/250/ffffff/000000'
];
var CategoryB = [
  'http://lorempixel.com/g/400/200/',
  'http://lorempixel.com/g/400/200/sports/'
];
$(function() {
  //Append array of images to list container in alphabetical Order
  BrandNameArray.forEach(function(cur, index, arr) {
    var img = document.createElement('img');
    img.src = cur;
    docFrag.appendChild(img);
  });
  container.appendChild(docFrag);
});

function CatA() {


  //Append array of images to list container in alphabetical Order
  CategoryA.forEach(function(cur, index, arr) {
    var img = document.createElement('img');
    img.src = cur;
    docFrag.appendChild(img);
  });
  container.appendChild(docFrag);

}

function CatB() {

  CategoryB.forEach(function(cur, index, arr) {
    var img = document.createElement('img');
    img.src = cur;
    docFrag.appendChild(img);
  });
  container.appendChild(docFrag);
}
.Container {
  position: absolute;
  top: 300px;
  left: 300px;
  height: 600px;
  width: 1260px;
}
.innerScroll {
  position: relative;
  width: 1250px;
  height: 600px;
  font-size: 25px;
  color: #8d8989 !important;
  overflow-y: scroll;
}
#CatA {
  width: 400px;
  height: 350px;
}
#CatB {
  width: 400px;
  height: 350px;
}
<div id="ChooseBrand" align="center" style="position:absolute; width:1920px; height:1080px; background-repeat: no-repeat; display:none; z-index=3; top:0px; left:0px;">
  <div class="Container">
    <div id="list" class="innerScroll"></div>
  </div>
  <button id="CatA" onclick="CatA()">
  </button>
  <button id="CatB" onclick="CatB()">
  </button>

问题:

当我单击buttonA或buttonB中的任何一个时,相应的图像将添加到当前图像列表中。

例如,此时,在菜单页面:

1.)对所有图像进行排序和显示。

2.)当我点击按钮A时:来自categoryA数组的图像被添加到菜单图像的顶部列表中。

3.)当我点击按钮B时:来自categoryB数组的图像被添加到菜单图像的顶部列表和显示的categoryA图像。

因此,所有图像都只是添加到每个显示的列表上。

因此,在这个时间点,存在附加的和重复的图像。 想问一下,我如何能够如上所述纠正这个问题?

谢谢。请帮助。


Functionality:

When users enter the main menu page, the set of image items are already arranged and displayed in alphabetical order. User can then get to choose different category buttons, Button A will return a set of images with the same sorting alphabetical order while button B will return another set of images with the same sorting alphabetical order.

What have I done

I have 3 sets of array of image source:

1.) All images source 2.) ButtonA category images source 3.) ButtonB category image source

I have grab all images from array(All images source), and insert into a particular location say: <div class="Container"><div id= "list" class="innerScroll"></div></div>. The images are then displayed in accordance to alphabetical order.

This is the code for your perusal.

var BrandNameArray = ['http://lorempizza.com/380/240',
  'http://dummyimage.com/250/ffffff/000000',
  'http://lorempixel.com/g/400/200/',
  'http://lorempixel.com/g/400/200/sports/'
];

var CategoryA = ['http://lorempizza.com/380/240',
  'http://dummyimage.com/250/ffffff/000000'
];
var CategoryB = [
  'http://lorempixel.com/g/400/200/',
  'http://lorempixel.com/g/400/200/sports/'
];
$(function() {
  //Append array of images to list container in alphabetical Order
  BrandNameArray.forEach(function(cur, index, arr) {
    var img = document.createElement('img');
    img.src = cur;
    docFrag.appendChild(img);
  });
  container.appendChild(docFrag);
});

function CatA() {


  //Append array of images to list container in alphabetical Order
  CategoryA.forEach(function(cur, index, arr) {
    var img = document.createElement('img');
    img.src = cur;
    docFrag.appendChild(img);
  });
  container.appendChild(docFrag);

}

function CatB() {

  CategoryB.forEach(function(cur, index, arr) {
    var img = document.createElement('img');
    img.src = cur;
    docFrag.appendChild(img);
  });
  container.appendChild(docFrag);
}
.Container {
  position: absolute;
  top: 300px;
  left: 300px;
  height: 600px;
  width: 1260px;
}
.innerScroll {
  position: relative;
  width: 1250px;
  height: 600px;
  font-size: 25px;
  color: #8d8989 !important;
  overflow-y: scroll;
}
#CatA {
  width: 400px;
  height: 350px;
}
#CatB {
  width: 400px;
  height: 350px;
}
<div id="ChooseBrand" align="center" style="position:absolute; width:1920px; height:1080px; background-repeat: no-repeat; display:none; z-index=3; top:0px; left:0px;">
  <div class="Container">
    <div id="list" class="innerScroll"></div>
  </div>
  <button id="CatA" onclick="CatA()">
  </button>
  <button id="CatB" onclick="CatB()">
  </button>

Issue:

When I click on either of buttonA or buttonB, the respective images are added onto the current list of images.

For Example, at this point in time, at the menu page:

1.) all images are sorted and displayed.

2.) when I clicked on the button A: the images from categoryA array is added into the list ontop of the menu image.

3.) when I clicked on the button B: the images from categoryB array is added into the list ontop of the menu image and categoryA image that is displayed.

Hence, all the images are just adding onto each displayed list.

Hence, at this point in time, there are additional and repeated image. Would like to ask, how am I able to rectify the issue as described?

Thanks.please help.


原文:https://stackoverflow.com/questions/36348068
更新时间:2022-08-22 22:08

最满意答案

它既不是iOS也不是fancybox问题。

除了你的验证问题,如

Mismatch between Public and System identifiers in the DOCTYPE declaration

...因为你有:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

......当你应该:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

...(如果你能看到差异)你的http://creactor.nl/script/javascript.js文件中还有一些与iOS有冲突的行:

var myLinks = document.getElementsByTagName('a');
for(var i = 0; i < myLinks.length; i++){
   myLinks[i].addEventListener('touchstart', function(){this.className = "hover";}, false);
   myLinks[i].addEventListener('touchend', function(){this.className = "";}, false);
}

我不是iOS的专家,所以我不能告诉你如何重写这些行,但如果你把它们隔离,那么fancybox就可以了。

我对你的网站进行了一次小清理,包括设置一个合适的DOCTYPE并重新组织脚本顺序,并注释掉上面的那些行,fancybox工作正常(在我的iPad中)。

检查JSFIDDLE


It's neither an iOS or a fancybox issue.

Apart from your validation issues like

Mismatch between Public and System identifiers in the DOCTYPE declaration

... because you have :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

... when you should have :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

... (if you can see the difference) you also have some lines that make fancybox conflict with iOS in your http://creactor.nl/script/javascript.js file :

var myLinks = document.getElementsByTagName('a');
for(var i = 0; i < myLinks.length; i++){
   myLinks[i].addEventListener('touchstart', function(){this.className = "hover";}, false);
   myLinks[i].addEventListener('touchend', function(){this.className = "";}, false);
}

I am not an expert in iOS so I can't tell you how to re-write these lines but if you isolate them, then fancybox will work just fine.

I did a small clean-up to your site, including setting a proper DOCTYPE and reorganizing the scripts order, and commented out those lines above and fancybox works fine (in my iPad).

Check JSFIDDLE

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)