代码之家  ›  专栏  ›  技术社区  ›  Jourkey

Drupal CCK添加另一个项目回调

  •  2
  • Jourkey  · 技术社区  · 15 年前

    我正在尝试在CCK多值字段上执行“添加另一个项”时使最后一个字段项成为焦点。

     $("#node-form table.content-multiple-table tr.draggable input[type='text']").live("keydown", function (e) {
      if (e.which == 13) {
       $(this).closest("table.content-multiple-table").siblings("div.content-add-more").find("input.form-submit").mousedown();
       $(this).closest("tr.draggable").next().find("input[type='text']").trigger("focus");
       return false;
      }
     });
    

    显然,这不起作用,因为字段是根据AHAH响应创建的。:(

    有人知道如何进入反应集中最后一个领域吗?谢谢。

    4 回复  |  直到 15 年前
        1
  •  3
  •   Jeremy French    15 年前

    你应该用 Drupal.behaviors Drupal应该为您附加这些行为。模块应该在修改DOM(包括AHAH请求)之后重新运行它们。

    在您的例子中,您可能需要添加两个行为,一个添加到按钮以标记它已被按下,另一个添加到最后一个字段以在设置标志时聚焦(并取消设置标志)。

        2
  •  1
  •   Semiaddict    15 年前

    查看的源代码 cck/includes/content.node_form.inc.公司 内容添加更多内容 功能:

      // Build our new form element for the whole field, asking for one more element.
      $form_state['item_count'] = array($field_name => count($_POST[$field_name]) + 1);
      $form_element = content_field_form($form, $form_state, $field);
      // Let other modules alter it.
      drupal_alter('form', $form_element, array(), 'content_add_more_js');
    

    我还没试过。。。


    Semiaddict

        3
  •  0
  •   Nikit    15 年前

    使用最后一个: http://api.jquery.com/last

        4
  •  0
  •   aendra    13 年前

    我也有类似的问题(在D6中;D7可能不同)。钥匙在换

    jQuery(document).ready(function(){
    //your stuff happens
    });
    

    Drupal.behaviors.myModuleBehavior = function (context) {
    //your stuff happens
    };