按钮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
最满意答案
它既不是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
相关问答
更多-
你可以做的是验证IF页面是否已经在fancybox中打开,并执行适当的fancybox方法,否则只需使用常规的javascript方法(即window.close() ) 话虽如此,在打开的页面中(通过window.open()或fancybox),你可能有一个函数来关闭它 function closePopup(){ window.close(); } 与关闭按钮/链接相关联 Close Window ...
-
Fancybox脚本无法正常工作(Fancybox script not working)[2022-03-25]
错误消息是: Uncaught TypeError: Object #has no method 'fancybox' 这意味着fancybox没有加载。 仔细看看你的来源我们看到你可以看到使用x -ecmascript而不是javascript。 改变这一点,你应该没事。 The error messag ... -
它既不是iOS也不是fancybox问题。 除了你的验证问题,如 Mismatch between Public and System identifiers in the DOCTYPE declaration ...因为你有: ......当你应该:打开你的控制台(F12)并注意错误? Fancybox似乎使用$.browser ,它在jQuery 1.9中删除了,这是一个错误! 另外, $("a#contactus").fancybox(); 是个错误! 没有这样的元素,你有一个div与该ID? Open your console (F12) and notice the errors? Fancybox seems to use $.browser, which was removed in jQuery 1.9, and that's an er ...修改了JFK用我的原始代码所说的内容,最终结果,它完美地运行: 不知道如何正确地感谢JFK,因为他没有回答这个问题... Modified what JFK had stated with what my original code was ...错误是: Uncaught TypeError: Object [object Object] has no method 'fancybox' 删除1个jQuery实例(您正在加载它两次)并按以下顺序加载脚本: //ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js /js/fancybox/jquery.fancybox-1.3.4.pack.js /js/fancybox/jquery.mousewheel-3.0.4.pack.js ( ...我建议你忘记.click()方法并使用fancybox媒体助手。 然后以正常方式将选择器绑定到fancybox。 这是你的调整代码: jQuery(document).ready(function ($) { $("#videos a.fancybox").fancybox({ padding: 0, // autoScale: ...
基本的Fancybox实现(Basic Fancybox Implementation)[2022-03-03]
在这些情况下,您应该始终关注开发者控制台的任何线索。 就你而言,消息说: TypeError:$(...)。on不是函数 这意味着该功能“on”不存在。 jQuery文档 - http://api.jquery.com/on/ - 就是这样说的 版本添加:1.7 所以,你需要高于1.7的jQuery版本才能使它工作。 In those situations you should always look at developer console for any clue. In your case, the ...我试图在你的CSS中取消选择这套规则,并且已经有效了。 :root, *, body, html { -webkit-transition:all 200ms linear; -khtml-transition:all 200ms linear; -moz-transition:all 200ms linear; -o-transition:all 200ms linear; transition:all 200ms linear; } 如果添加删除fancybox转换 ...延迟FancyBox打开* WITH *“不再显示此”链接(Delayed FancyBox open *WITH* “don't show this again” link)[2022-08-23]
你几乎得到了它,但有几个问题: 最重要的是,你错过了jquery.cookie依赖! 这个插件被js-cookie取代。 将其包含在您的页面中,例如: 你的html和JS之间有一些不匹配的大小写:注意testBox和testBox 否则,你很好走! 这是一个工作小提琴: http : //jsfiddle.net/memeLab/ ...相关文章
更多- 我一点onclick为什么总是提交表单
- 用‘button’跟‘text’组合代替‘file’,选择文件后点‘submit’,‘file’的值被清空
- Heritrix源码分析(二) 配置文件order.xml介绍
- 微信公众号接口添加菜单时错误(errcode":40017 invalid button type)
- MyBatis动态参数order by的设置
- Heritrix源码分析(三) 修改配置文件order.xml加快你的抓取速度
- 请教javascript问题
- WeixinJSBridge实现退出微信浏览器
- HTML5 Canvas 图像动画的实现
- 小强的HTML5移动开发之路(38)——jqMobi插件ActionSheet
最新问答
更多- 您如何使用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)