2014-09-06 172 views
0

我正在編輯Angularjs xeditable的一些用戶。我希望在單擊可編輯元素時選擇文本。 我想我知道如何編寫指令:編輯時選擇文本

UserManager.directive('selectWhenEditing',function(){ 
     var linkFunction = function(scope,element,attributes) 
     { 
      console.log(element.find('span')); 
      console.log(element.find('.editable')); 
      element.find('.editable').on('click',function(){ 
       element.find('.editable-input').select(); 
       console.log("launched"); 
      }); 
     }; 
     return{ 
      restrict: 'A', 
      link:linkFunction 
     };} 
    ); 

這是我的來電顯示元素:

<td data-select-when-editing=""> 
<span class="ng-scope ng-binding editable editable-click" onbeforesave="checkUsername($data,user)" editable-text="user.username"> Name </span> 
</td> 

看來,find()方法沒有找到類「編輯」(但它例如找到跨度)。雖然正如你可以在我的html代碼中看到的那樣,但可編輯類應用於跨度,因此它應該由find()找到。

回答

0

檢查此鏈接並瞭解它仔細http://jsfiddle.net/mahbub/XRL4U/

<a xeditable...></a> 
+0

謝謝你,但實際上這個問題不是指令,但它並沒有得到我我想要的find方法... – Eagle1 2014-09-08 19:41:29

相關問題