Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.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/8/.htaccess/5.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
我的url哈希是否定义为jquery数据?_Jquery - Fatal编程技术网

我的url哈希是否定义为jquery数据?

我的url哈希是否定义为jquery数据?,jquery,Jquery,我正在根据url中传递的哈希触发javascript 但是如果散列不是我期望的,我就不想触发它 使用数据类别属性定义期望散列的列表 如何获取该数据的数组,以便查看哈希是否在数组中 以下是我收到的HTML: <div class="filter_padder" id="nav_channels"> <div class="filter_wrapper" style="max-width:650px;"> <div cla

我正在根据url中传递的哈希触发javascript

但是如果散列不是我期望的,我就不想触发它

使用
数据类别
属性定义期望散列的列表

如何获取该数据的数组,以便查看哈希是否在数组中

以下是我收到的HTML:

    <div class="filter_padder" id="nav_channels">
        <div class="filter_wrapper" style="max-width:650px;">
            <div class="filter selected" data-category="cat-all">ALL</div>
            <div class="filter" data-category="MusicWorld">MusicWorld</div>
            <div class="filter" data-category="Awards">Awards</div>
            <div class="filter" data-category="MX">Exchange</div>
            <div class="filter last-child" data-category="Com">Community</div>
            <div class="clear"></div>
        </div>
    </div>
但是我不知道如何动态地构建元素列表来与“hash”进行比较。我认为这大致是这样的:

$('#nav_channels').data('category');
但无法使其工作。

尝试以下方法:

var hash = location.hash.replace('#', '');
if( $('.filter[data-category="'+hash+'"]').length ) { 
  doSomething();
};

您可以将值放入数组,如下所示:

var cats = $('[data-category]').map(function() {
    return $(this).data('category');
}).get();
var cats = $('[data-category]').map(function() {
    return $(this).data('category');
}).get();