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

查看:20
本文介绍了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.

最大的问题 ...是,一旦我让 jQ 工作,它就会影响列表/提要中的每个可见节点,因为我通过 div id 或类调用该函数.我理解为什么会发生这种情况,但我无法弄清楚如何让 jQ 仅对按下按钮的节点产生影响.

And the biggest problem ... is that once I get the jQ to work it effects every visible node in the list/feed since im calling the function via a div id or a class. I understand why this is happening but what i can't figure out is how to get the jQ to make an impact only on the node in which the button is being pressed.

这是我迄今为止在我的节点模板中针对特定内容类型的内容:

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 类的对象来切换标志.

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天全站免登陆