Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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 find()&;动态元素上的each()_Javascript_Jquery_Html - Fatal编程技术网

Javascript jQuery find()&;动态元素上的each()

Javascript jQuery find()&;动态元素上的each(),javascript,jquery,html,Javascript,Jquery,Html,我有一个元素,它包含多个使用jQuery/Ajax动态填充的其他,我试图运行以下代码,但find()无法获取其中任何一个 这是填充数据之前的HTML样板 <input type="text" id="inv-filter" class="form-control"> <div class="row itemList" style="margin-right: -2px;margin-left:-2px;"> </div> 我在控制台调试器中运行了多个测试,

我有一个
元素,它包含多个使用jQuery/Ajax动态填充的其他
,我试图运行以下代码,但
find()
无法获取其中任何一个

这是填充数据之前的HTML样板

<input type="text" id="inv-filter" class="form-control">
<div class="row itemList" style="margin-right: -2px;margin-left:-2px;">

</div>

我在控制台调试器中运行了多个测试,例如
$('.itemList').length()
等。。但似乎找不到任何结果&在我的输入字段中输入文本时,什么都没有发生

您能将代码转换为工作片段,或创建一个小提琴吗?它将帮助人们快速解决您的问题。
sell item
shop item
$(this)。数据('hash')。toLowerCase()
,而不是
$(this)。数据('hash')。text().toLowerCase()
数据('hash')返回一个没有
text()
方法的字符串
$sellContainer.find('.sell-item').each(function() { //replace sell-item with shop-item
        if (!$(this).hasClass('selected') && $(this).data('hash').text().toLowerCase().includes(search)) {
            $(this).show();
        } else {
            $(this).hide();
        }
    });
$('#inv-filter').keyup(function() {
    var search = $(this).val().toLowerCase();
    var $sellContainer = $('.itemList');
    if (search.trim() === '') {
        $sellContainer.find('.shop-item').show();
        $sellContainer.find('.shop-item.selected').hide();
        return;
    }
    $sellContainer.find('.sell-item').each(function() {
        if (!$(this).hasClass('selected') && $(this).data('hash').text().toLowerCase().includes(search)) {
            $(this).show();
        } else {
            $(this).hide();
        }
    });
});
$sellContainer.find('.sell-item').each(function() { //replace sell-item with shop-item
        if (!$(this).hasClass('selected') && $(this).data('hash').text().toLowerCase().includes(search)) {
            $(this).show();
        } else {
            $(this).hide();
        }
    });