2011-10-05 31 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);