【问题标题】:Dropdown won't select and open div... What am I doing wrong?下拉菜单不会选择并打开 div ......我做错了什么?
【发布时间】:2015-06-30 13:26:36
【问题描述】:

在我们的Offices 页面上,如果您单击地图上的点,它会在下面打开一个 div 并更改侧边栏的内容。我们添加了一个下拉菜单,以便您可以在手机上选择城市。由于我重新创建了网站并复制了代码,所以我做了一些事情,但它不再起作用了。

我知道问题与这段代码有关

$('#continent').change(function() {
    $('.targetDiv').hide();
    $('#worldwide').hide();
    var target = $("select option:selected").attr('target');
    var value = $("select option:selected").attr('value');
    console.log($('#' + value));
    $(".detail-container").empty();
    $('#' + value).clone().show().appendTo(
        ".detail-container");
    $('#div' + target).show();
    if (value == "worldwide") {
        $('.slidingDiv').slideUp();
    }
});

这是完整的代码

jQuery(function($) {

    $(".dot").show();

    $('.dot').click(function() {

        $(".slidingDiv").slideDown('slow');

    });

    $('#continent').change(function() {
        $(".slidingDiv").slideDown('slow');
    });
});

jQuery(function($) {

    $('#showSingle').click(function() {

        $('.targetDiv').show();

    });

    $('.dot').click(function() {
        $('.targetDiv').hide();
        $('#div' + $(this).attr('target')).show();
        var value = $(this).attr('city');
        $(".detail-container").empty();
        $('#' + value).clone().show().appendTo(
            ".detail-container");
        $('#' + value).show();
        $('#continent').val(value);
    });

    $('#continent').change(function() {
        $('.targetDiv').hide();
        $('#worldwide').hide();
        var target = $("select option:selected").attr('target');
        var value = $("select option:selected").attr('value');
        console.log($('#' + value));
        $(".detail-container").empty();
        $('#' + value).clone().show().appendTo(
            ".detail-container");
        $('#div' + target).show();
        if (value == "worldwide") {
            $('.slidingDiv').slideUp();
        }
    });

});

我相信这对于懂 Javascript 的人来说很简单。

谢谢。

【问题讨论】:

  • 你应该检查控制台是否有错误 - Uncaught ReferenceError: getenv is not defined 首先修复它。这很可能是唯一的问题。
  • 我查过了,这与调用分析有关,所以它不应该影响它。

标签: javascript jquery html dictionary


【解决方案1】:

你去吧:

$('#continent').change(function() {
        $('.targetDiv').hide();
        $('#worldwide').hide();
        var target = $("#continent").find(":selected").attr('target');
        var value = $("#continent").val();
        console.log($('#' + value));
        $(".detail-container").empty();
        $('#' + value).clone().show().appendTo(
            ".detail-container");
        $('#div' + target).show();
        if (value == "worldwide") {
            $('.slidingDiv').slideUp();
        }
    });

应该可以,但我猜这是非常丑陋的代码:P

【讨论】:

  • 谢谢!!你太棒了!!完美运行。
猜你喜欢
  • 1970-01-01
  • 2014-11-28
  • 2016-09-04
  • 1970-01-01
  • 2020-05-02
  • 1970-01-01
  • 1970-01-01
  • 2020-08-05
相关资源
最近更新 更多