2014-07-23 3 views
0

문서를 통해 특정 클래스를 검색해야하고 해당 클래스를 클릭 할 때 편집자를 초기화해야하는 경우가 있습니다.Redactor는 한 번에 하나의 인스턴스 만 표시합니다.

나는 횡단 HTML로 이런 짓을하고

$(".contenteditor").redactor({ 
    toolbarExternal: '.commoneditor', 
    toolbarFixed: true, 
    focus  : true, 
    imageUpload : 'image_upload.php', 
    css   : "http://localhost/template/css/basictemplatepage.css", 
}); 

이 같은 클래스에 더 이상의 요소가 모두가 편집자를 트리거해야 가정하자. 이 경우 제대로 작동하지 않는 하나 이상의 인스턴스가 있습니다. 난 이전의 모든 인스턴스를 파괴하고 하나의 인스턴스 만 유지하려고합니다. 어떻게 할 수 있습니까 ??

답변

0

clicked 요소를 참조하는 this 키워드를 사용하여 click에서 편집자를 인스턴스화 할 수 있습니다.

$(".contenteditor").on('click', function(event){ 

$(this).redactor({ 
    toolbarExternal: '.commoneditor', 
    toolbarFixed: true, 
    focus  : true, 
    imageUpload : 'image_upload.php', 
    css   : "http://localhost/template/css/basictemplatepage.css", 
}); 
}); 
+0

는 거의 같은 일을 한 $ (이) .addClass ("contenteditor"); 그리고이 추가 된 클래스를 사용하여 편집기를 호출합니다. –