gpt4 book ai didi

javascript类检查

转载 作者:太空宇宙 更新时间:2023-11-03 19:52:53 26 4
gpt4 key购买 nike

这有点难以解释,但我会尽力而为。我有一堆链接

<li><a class="various fade "  href="FOOTWEAR_SUB_PAGES/NIKE_SNOW.html"> <img src="MAIN_IMAGES/ZOOM_FORCE_2.jpg" border="0"/></a></li>                   
<li><a class="various1 fade " href="FOOTWEAR_SUB_PAGES/MERCURIAL_SUPERFLY.html"><img src="MAIN_IMAGES/MERCURIAL_SUPERFLY-2.jpg" border="0" /></a></li>
<li><a class="various2 fade " href="FOOTWEAR_SUB_PAGES/AIRMAX_MOTO.html"><img src="MAIN_IMAGES/AIRMX-2.jpg" border="0" /></a></li>
<li><a class="various3 fade " href="FOOTWEAR_SUB_PAGES/le-coq-joakim-noah.html"><img src="MAIN_IMAGES/JOAKIM-NOAH-3.jpg" border="0" /></a></li>
<li><a class="various4 fade " href="FOOTWEAR_SUB_PAGES/NIKE_BMX.html"><img src="MAIN_IMAGES/GYZIRO-3.jpg" border="0" /></a></li>

和另一组链接

<a class="ex1 various" href="FOOTWEAR_SUB_PAGES/NIKE_SNOW.html">ZOOM FORCE ONE ///</a>            
<a class="ex1 various1" href="FOOTWEAR_SUB_PAGES/MERCURIAL_SUPERFLY.html">MERCURIAL SUPERFLY ///</a>
<a class="ex1 various2" href="FOOTWEAR_SUB_PAGES/AIRMAX_MOTO.html">AIRMX MOTO BOOT ///</a>
<a class="ex1 various3" href="FOOTWEAR_SUB_PAGES/le-coq-joakim-noah.html">JOAKIM NOAH ///</a>
<a class="ex1 various4" href="FOOTWEAR_SUB_PAGES/NIKE_BMX.html">DUNK GYRIZO</a>

现在当有人点击这些链接中的任何一个时,这个 js 就会被调用。

$(document).ready(function () {

$("ul#gallery li a").each(function (i, item) {
var url = $(item).attr("href");
var links = $("a.ex1.various");
var link = $(links.parent().find("a[href='" + url + "']"));
var redclass = "showing-in-gallery";
var gallery = $("#gallery");
var scroll = function () {

link.addClass(redclass);
gallery.animate({ left: -1 * $(item).position().left }, 1500);
gallery.css("width", gallery.width() + 640 + "px");
$(item).parent().after('<li id="gallery_spacer" style="width: 640px;"></li>');

imageIndex = $(".ex1").index($(this));
imageIndex = $(".fade").index($(this));


setGalleryLinks();

};

$(this).bind("click", scroll);
link.bind("click", scroll);
});

如何检查是否单击了 .ex1 或 .fade?比如

    if (ex1 clicked){   
imageIndex = $(".ex1").index($(this));}
if (fade clicked){
imageIndex = $(".fade").index($(this));}

任何帮助都是救命稻草,我已经花了好几天时间来解决这个问题。

最佳答案

使用这个:

if ($(e.target).hasClass('fade'))
// something
else
// something else

将事件参数添加到scroll 函数:

var scroll = function (e) {

关于javascript类检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14085494/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com