简体   繁体   English

jQuery插件tinysort不起作用,不确定为什么

[英]Jquery plugin tinysort isn't working, not sure why

This is the live site I'm messing around with. 这是我正在玩的实时站点

The numbers which are on each picture are called via get_field() using php. 每张图片上的数字使用php通过get_field()进行调用。 (I'm using plugin "Advanced custom fields" to create a field where I enter a number when creating a post, in this case it's the protein amount. Then I call it with php so that it displays on top of picture like so: (我正在使用插件“高级自定义字段”创建一个字段,在创建帖子时在其中输入数字,在这种情况下,它是蛋白质量。然后用php调用它,使其显示在图片顶部,如下所示:

<?php
$protein = get_field('grams_of_protein');
?>

<div class="portfoliooverlay"><a href="<?php the_permalink(); ?>"><span class="jrm-protein"><?php echo "$protein"; ?></span></a></div>

I added a span class of .jrm-protein so that I can target the spans of all the visible posts on the page since they all have the same html structure and all contain .jrm-protein. 我添加了一个.jrm-protein跨度类,以便我可以定位页面上所有可见帖子的跨度,因为它们都具有相同的html结构并且都包含.jrm-protein。

I am trying to use the jquery plugin TinySort 我正在尝试使用jquery插件TinySort

The button in the sidebar on the site labeled "sort" has the following JS: 网站上侧栏中标记为“ sort”的按钮具有以下JS:

jQuery(document).ready(function() {

jQuery('#sorting-button').click(function() {
        jQuery('.jrm-protein').tsort();
    });
});

Can someone take a look at the site, and figure out why it isn't working? 有人可以看看这个网站,弄清楚为什么它不起作用吗?

I didn't register the plugin script, just enqueued it like this in my functions.php 我没有注册插件脚本,只是在我的functions.php中将其排队

wp_enqueue_script( 'jrm-custom-tinysortjs', get_template_directory_uri() . '/js/jrmcustomtinysort.js', array('jquery'), false );
wp_enqueue_script( 'jrm-customjs', get_template_directory_uri() . '/js/jrmcustom.js', array('jquery'), false );

On a side note, I added an overlay to the entire page that toggles when the button is clicked, just to make sure and show you that the JS file is working. 附带说明一下,我在整个页面上添加了一个叠加层,单击该按钮时会进行切换,以确保并向您显示JS文件正在运行。 Or at least the second one is. 或者至少第二个是。

================================================================================= ================================================== ==============================

Update: I added a div with a bunch of spans at the bottom, and it works with those, so I guess the question is how can i get it to work across different containers? 更新:我在底部添加了一个带有一连串跨度的div,并且可以使用这些跨度,所以我想问题是如何使它跨不同的容器工作? Should just be a selector issue (but not sure how to do it) 应该只是选择器问题(但不确定如何做)

I don't plan on debugging your whole site, but I'll help with the first error I see: 我不打算调试您的整个网站,但会为您看到的第一个错误提供帮助:

Uncaught TypeError: Cannot call method 'getElementsByTagName' of null

var container = document.getElementById( 'site-navigation' ),
    button    = container.getElementsByTagName( 'h1' )[0],
    menu      = container.getElementsByTagName( 'ul' )[0];

You're setting container to a single element, not the document object. 您将容器设置为单个元素,而不是document对象。 Either change container on the other 2 lines to document or change 更改其他两行上的container以进行document或更改

var container = document.getElementById( 'site-navigation' ),

to

var container = document,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM