2011-11-14 3 views
0

형식화 된 텍스트를 표시하기 위해 ckeditor를 사용하고 있습니다. 위의 목적으로 Asp.net mvc 3 면도기 도우미 메서드 Html.CKEditorFor (x => x.Description)를 사용하고 있습니다 .I , 목적을 위해 다음 코드를 사용하고이 ckeditor.I의 워터 마크 기능을 구현하기 위해CKEditor를 사용하여 텍스트 상자에서 포커스 이벤트가 실행되지 않습니다.

$("#Description").focus(function() { 

    $(this).filter(function() { 

     // We only want this to apply if there's not 
     // something actually entered 
     return $(this).val() == "" || $(this).val() == "Type here" 

    }).removeClass("watermarkOn").val(""); 

});  

필요하지만 포커스 이벤트는 내가 ckeditor에 초점을 때 내가 불을 지르고를 사용하여 문서를 검사 textbox.So 해고하지 않고 기본 텍스트가 mvc ckeditor helper에 의해 생성 된 다음 클래스 ('cke_show_borders') 안에 렌더링 된 것을 발견했습니다. 위 코드를

로 수정했습니다. 10
$(".cke_show_borders").focus(function() { 
    $(this).filter(function() { 

     // We only want this to apply if there's not 
     // something actually entered 
     return $(this).val() == "" || $(this).val() == "Type here" 

    }).removeClass("watermarkOn").val(""); 

}); 

그러나 여전히 포커스 이벤트가 발생하지 않습니다. 내가 잘못 가고있어 pls는 긴급한 도움을줍니다. 감사합니다. .

$(function() { 
    $('.cke_show_borders').focus(function() { 
     $(this).filter(function() { 
      // We only want this to apply if there's not 
      // something actually entered 
      return $(this).val() == '' || $(this).val() == 'Type here'; 
     }).removeClass('watermarkOn').val(''); 
    }); 
}); 

답변

0

확인 을 사용하여 jQuery 대신 API를 사용합니다. developer features을 확인 했습니까? 당신과 같이 자신의 onfocus 및 이벤트를 수정할 수, 마찬가지로

var editor = CKEDITOR.replace('ckeditor'); 
editor.on('instanceReady', function(e) { 
    // customize stuff here 
    // this.document.$.childNodes[1].childNodes[1].style.styleName = 'value'; 
    editor.focus(); 
}); 

:

editor.on('focus', function(e) { 
    // code here 
}); 
+0

안녕 모든 돼고가 유지되었습니다

덧붙여, 내가 본 사람들은 같은 것을 사용하여 CKEditor의 기본 동작을 변경 문서 준비 기능에서. – user1045002

2

내 추측은이 작업을 수행하도록해야한다는 것입니다 : 당신이 어떤 이벤트를 구독 할 시도하기 전에 DOM이 완전히로드되었는지 확인하기 위해 $(document).ready 핸들러에서이 코드를 배치 한 것을

+0

안녕하세요. 위 코드를 구현했지만 mozilla firefox console.Error : uncaught exception : [CKEDITOR.editor.replace]에 다음 오류가 표시되었습니다. id 또는 "ckeditor"라는 이름의 요소를 찾을 수 없습니다. – user1045002

+0

아, 네가 '텍스트 편집기'태그에 준 'id'가 무엇이든 'ckeditor'를 변경해야합니다. –

+0

안녕하세요 모든 것들은 문서 준비 함수에 보관되어 위의 방법을 따랐을 때 초점 이벤트가 발생하지만 문제는 반환 문이 true를 반환하면 ckeditor에 적용된 클래스 (watermarkOn)를 제거 할 수 없습니다. – user1045002

관련 문제