Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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
Javascript Jquery没有';不要在第一次单击时隐藏元素_Javascript_Jquery_Html - Fatal编程技术网

Javascript Jquery没有';不要在第一次单击时隐藏元素

Javascript Jquery没有';不要在第一次单击时隐藏元素,javascript,jquery,html,Javascript,Jquery,Html,我有一个奇怪的问题,我有一个事件侦听器 $(document).on('click', '.suggested-location-item', function(event) { event.preventDefault(); $('#IDsuggestedLocationsList').html(''); $('#IDlocationSuggestBox').hide(); }); 因此,当.suggered location项单击一次(1次)时,元素不会消失,它

我有一个奇怪的问题,我有一个事件侦听器

$(document).on('click', '.suggested-location-item', function(event) {
    event.preventDefault();
    $('#IDsuggestedLocationsList').html('');
    $('#IDlocationSuggestBox').hide();


});
因此,当.suggered location项单击一次(1次)时,元素不会消失,它只会快速闪烁,只会在第二次单击时消失。但是,如果我执行
$('#IDlocationSuggestBox')。remove()
而不是hide(),它在第一次单击时删除元素,没有问题。我将在这里发布我的全部代码,因为可能是其他一些代码导致了问题:

此代码生成以下元素:

$(document).on('propertychange change click keyup input paste', '#IDLocationSearchInput', function(event) {
    event.preventDefault();
    var searchTerm = $('#IDLocationSearchInput').val();
    $.ajax({
        url: IDurlToGetLocation,
        type: 'GET',
        data: {'location':searchTerm},
    })
    .done(function(data) {
        if (data.success == 0) {
            $('#IDlocationSuggestBox').hide();
            $('#IDsuggestedLocationsList').html('');
            if (data.message) {
                $('#IDlocationSuggestBox').show();
                $('#IDsuggestedLocationsList').html("<div class='list-group-item'>"+data.message+"</div>");
            }
        }else{
            $('#IDlocationSuggestBox').show();
            $('#IDsuggestedLocationsList').html('');

            $.each(data, function(index, val) {

                $('#IDsuggestedLocationsList').html($('#IDsuggestedLocationsList').html()+"<a href='' type='"+val.table_name+"' id='"+val.id+"' class='list-group-item suggested-location-item'>"+val.city_name+"</a>");
            });
        }


    });

});
请帮忙,这是个奇怪的问题


谢谢。

我发现一个打字错误,我应该在我的电脑上使用
点击输入
绑定

$(document).on('propertychange-change-click-keyup-input-paste','IdleLocationSearchInput',函数(事件){…})


事件侦听器

我发现一个输入错误,我应该在我的

$(document).on('click', '.suggested-location-item', function(event) {
    event.preventDefault();
    $('#IDsuggestedLocationsList').html('');
    $('#IDlocationSuggestBox').hide();


});
$(document).on('propertychange-change-click-keyup-input-paste','IdleLocationSearchInput',函数(事件){…})


事件侦听器

在ajax调用后,是否再次显示?为什么要绑定
'propertychange click keyup input paste'
,只使用
input
,这就足够了。是的,除了要隐藏的元素外,所有东西都按它应该的方式工作。hide()需要2次单击而不是1次,因为绑定错误,请仅在
input
上使用,否则将触发
hide()事件
。谢谢你,兄弟,我现在只剩下“点击输入”了!在ajax调用之后,它会再次显示吗?为什么要绑定
'propertychange click keyup input paste'
,只使用
input
,这就足够了。是的,除了要隐藏的元素外,所有东西都按它应该的方式工作。hide()需要2次单击而不是1次,因为绑定错误,请仅在
input
上使用,否则将触发
hide()事件
。谢谢你,兄弟,我现在只剩下“点击输入”了!
$(document).on('click', '.suggested-location-item', function(event) {
    event.preventDefault();
    $('#IDsuggestedLocationsList').html('');
    $('#IDlocationSuggestBox').hide();


});