Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 可以添加活动类,但可以';似乎无法使用“下一步单击”功能删除它_Jquery - Fatal编程技术网

Jquery 可以添加活动类,但可以';似乎无法使用“下一步单击”功能删除它

Jquery 可以添加活动类,但可以';似乎无法使用“下一步单击”功能删除它,jquery,Jquery,晚上好。试图修改为显示/隐藏谷歌地图标记而编写的脚本。问题是,我需要向每个单击函数添加一个活动类,但在下一次单击事件发生时将其删除。我试过各种组合,但似乎都没用 以下是jQuery: $(document).ready(function() { $(".category-header").each(function() { $(this).click(function() { showCategory($(this).text(), $(this).parent().

晚上好。试图修改为显示/隐藏谷歌地图标记而编写的脚本。问题是,我需要向每个单击函数添加一个活动类,但在下一次单击事件发生时将其删除。我试过各种组合,但似乎都没用

以下是jQuery:

$(document).ready(function() {
  $(".category-header").each(function() {
    $(this).click(function() {
        showCategory($(this).text(), $(this).parent().addClass("active").attr("zoom"));
    })
  })
  $(".map-item").each(function() {
    $(this).click(function() {
        getMarker($(this).text(), $(this).addClass("active").attr('zoom'));
    })
  })
})

function showCategory(category, zoom) {
  category = String(category).toLowerCase();
  infowindow.close();
  $(".map-items-container").not($("#" + category + "-container .map-items-container")).slideUp();
  target = $(".map-category").has('.category-header:contains("' + category + '")');
  target.find($(".map-items-container")).slideDown();   
  var LatLngList = new Array (homemarker.getPosition());    
  for (var i=0; i<allMarkers.length; i++) {
    if (allMarkers[i].category == category) {
        allMarkers[i].setVisible(true);
        LatLngList.push(allMarkers[i].getPosition());
    } else {
        allMarkers[i].setVisible(false);
    }
  }
$(文档).ready(函数(){
$(“.category header”).each(函数(){
$(此)。单击(函数(){
showCategory($(this).text(),$(this.parent().addClass(“活动”).attr(“缩放”));
})
})
$(“.map项”)。每个(函数(){
$(此)。单击(函数(){
getMarker($(this.text(),$(this.addClass(“活动”).attr('zoom'));
})
})
})
功能显示类别(类别、缩放){
category=String(category.toLowerCase();
infowindow.close();
$(“.map items container”).not($(“#”+category+“-container.map items container”).slideUp();
target=$(“.map category”).has(“.category头:包含(“+category+”));
target.find($(“.map items容器”)).slideDown();
var LatLngList=新数组(homemarker.getPosition());
对于(var i=0;i
日常需要
鱼美容院
娱乐
购物
美国服装
任何帮助都将不胜感激。为了记录在案,我曾尝试切换Class和removeClass,但似乎无法使其与此脚本保持一致。

我删除了
。each()
,就像Anton在评论中说的那样

然后,我将适当的
removeClass(“active”)
添加到所有可以激活该类但不应该再激活该类的元素中

$(".category-header").click(function() {
    $(".category-header").parents().removeClass("active");
    showCategory($(this).text(), $(this).parent().addClass("active").attr("zoom"));
})


$(".map-item").click(function() {
    $(".map-item").removeClass("active");
    getMarker($(this).text(), $(this).addClass("active").attr('zoom'));
})

您不需要使用。each()只需直接绑定对元素的单击我也这么认为,但这会使我只需在addClass之前添加removeClass吗?什么元素具有“zoom”属性?使用addClass时,您也可以使用removeClass.Btw.attr(“zoom”)此处无效。创建数据缩放属性。缩放用于向代码附带的谷歌地图选择器添加属性。我在描述中提到它与谷歌地图有关。如果它可以使用数据缩放,我不知道这一点。如果我现在说我爱你会不会很奇怪?哈哈。这花了我太长时间很明显,两秒钟就可以解决问题了。非常感谢!我还不能接受这个答案,因为你太快了,但我会马上接受。谢谢!
$(".category-header").click(function() {
    $(".category-header").parents().removeClass("active");
    showCategory($(this).text(), $(this).parent().addClass("active").attr("zoom"));
})


$(".map-item").click(function() {
    $(".map-item").removeClass("active");
    getMarker($(this).text(), $(this).addClass("active").attr('zoom'));
})