Drupal 7 + jQuery,如何让jQuery只与活动节点(通过nid)进行交互,而不是列表中的每个节点 [英] Drupal 7 + jQuery, how to get jQuery to interact only with the active node (via nid) and not every node in the list

查看:134
本文介绍了Drupal 7 + jQuery,如何让jQuery只与活动节点(通过nid)进行交互,而不是列表中的每个节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在搜索很长时间没有运气,如果我错过了一个较旧的线程,请指出正确的方向。

I've been searching for a very long time without any luck within the subject, please point me in the right direction if I have been missing an older thread.

我想要实现的目标:

定期查看多个节点,并按一个节点内的按钮(或任何)使jQuery以任何方式与此特定节点进行交互。防爆。使一个隐藏的div出现。

Having a regular view of multiple nodes and by pressing a button (or whatever) within a node make jQuery interact with this specific node in any way. Ex. make a hidden div appear.

我面临的问题是初学者,我仍然发现很难与jQuery在一起工作与D7。我一直在使用jQ很久以前,但是当与D7一起使用时,我面临着重大的问题。

The problems I'm facing are for starters that I'm still finding it hard to work with jQuery together with D7. I've been using jQ for a very long time before but when using it together with D7 I'm facing major problems.

最大的问题是strong> ...是,一旦我得到jQ工作,它会影响列表/ feed中的每个可见节点,因为im通过div id或类调用该函数。我明白为什么会发生这种情况,但我无法想像的是如何让jQ仅对按下按钮的节点产生影响。

这是我在节点模板中到目前为止的具体内容类型:

This is what i have so far within my node-template for a specific content-type:

    <script type="text/javascript">                                         
(function ($) {

 $('.up2').click(function () {
        $('.nummer_dark').text(parseInt($('.nummer_dark').text())+1,0).toFixed(2);
   $('.up2').toggle();


      });

       $('.up').one('click', function() {
        $('.flag-link-toggle').click();once();


      });


})(jQuery);

 </script> 

这只是一个例子,我想通过按一个对象来增加一个跨度内的数字与up2类,并通过按up一个对象与up类切换一个标志。

This is just an example where I'm trying to increase the number within a span by pressing an object with the up2-class and toggle a flag by pressing an object with the up-class.

第一个代码工作,但数字增加与小数(2.453,3.4123等) )而不是我计划的1,2,3,4。但是主要的问题是这两个代码都在列表中的每一个节点都有效果。我知道这是因为列表中的每个节点都有相同的节点模板,因此相同的类,但是我想要找到一个解决方案使用jQ中的node-id。

The first code works but the number is increased with decimals ( 2.453, 3.4123 etc) instead of just 1,2,3,4 as i planned. But the main problem is that these both codes are giving effect on every node in the list.. I know this is because every node in the list have the same node-template and thus the same classes but i want to find a solution using the node-id in the jQ.

任何领先的答案都可以节省我的一天! =)

Any leading answers would save my day! =)

推荐答案

我将利用 .closest() .find() 方法。这将允许您仅查找包含刚被单击的按钮的父节点,以便您可以仅查找和更改该节点的子元素。这是一些快速的伪代码,显示如何工作。

I would make use of the .closest() and .find() methods. This will allow you to locate just the parent node containing the button that was just clicked so you can find and change just the child element of that node. Here is some quick psuedo code showing how it would work.

$('.up2').click(function() {
    $(this).closest('.node').find('.nummer_dark').text();
}

这篇关于Drupal 7 + jQuery,如何让jQuery只与活动节点(通过nid)进行交互,而不是列表中的每个节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆