2011-10-05 28 views
0

我正在使用Drupal 6.我需要将删除链接附加到dom。然后,我想在我刚刚添加的remove链接元素上使用Drupal.attachBehaviors。我将行为附加到此链接,以便我可以编写更多的JavaScript来处理此链接的点击。当我附上的行为,因为我有以下我得到Drupal.attachBehaviors:正确的参数? (javascript/jquery/Drupal 6)

第10行:未捕获的类型错误:Cannont调用方法的不确定

$(“#编辑现场产品裁判提供商-0“代替” -nid-nid“,context).val()返回null。如果我将下面的Drupal.attachBehaviors行注释掉,则错误消失,team_current具有我期望的值。

  1. 是我传递什么Drupal.attachBehaviors正确吗?
  2. 你能告诉我为什么Drupal.attachBehaviors行在var team_current行中导致错误吗? JavaScript之后产生

HTML运行:

<div class="form-item" id="edit-field-product-ref-provider-0-nid-nid-wrapper"> 

    <input type="text" name="field_product_ref_provider[0][nid][nid]" id="edit-field-product-ref-provider-0-nid-nid" size="60" value="bw11 [nid:631]" class="form-text form-autocomplete text noderelationships-nodereference-autocomplete noderelationships[field_product_ref_provider] noderelationships-processed nodeRefUi-processed" autocomplete="OFF"> 

    <div class="noderelationships-nodereference-buttons-wrapper"> 
    <a href="javascript:void(0)" class="noderelationships-nodereference-create-button" title="Create a new support team listing and assign it to this product">Create a new support team listing and assign it to this product</a> 
    <a href="javascript:void(0)" class="noderelationships-nodereference-remove-button" title="Remove support team from this product" style="">Remove support team from this product</a> 
    </div> 

</div> 

的Javascript:

(function ($) { 
    // Store our function as a property of Drupal.behaviors. 
    Drupal.behaviors.tsrNodeRefUi = function (context) { 

    var team_current = $("#edit-field-product-ref-provider-0-nid-nid", context).val().replace(/\s\[nid:\d+\]/, ''); 
    var remove_button = '<a href="javascript:void(0)" class="noderelationships-nodereference-remove-button" title="Remove support team from this product">Remove support team from this product</a>'; 

    //Add Remove link... 
    $(".noderelationships-nodereference-buttons-wrapper").append(remove_button); 

    //Attach Behaviors 
    Drupal.attachBehaviors($(".noderelationships-nodereference-remove-button")); 
    }; 
}(jQuery)); 

回答

1

你的最后一行:

Drupal.attachBehaviors($(".noderelationships-nodereference-remove-button")); 

应该是:

Drupal.attachBehaviors(remove_button);