맞습니다. textarea
을 덮어 씁니다. 해결책은 함수에 현재의 텍스트 영역을 통과하는 것입니다 : 현재의 텍스트 영역 이벤트 데이터 옵션을 통해 이벤트 핸들러에 전달되는 것을
$('div.editor-instance-' + i + ' div').live('click', {textarea: this}, function(e){
var type = $(this).attr('class').substr(4);
switch (type) {
case 'bold':
simpleReplace(e.data.textarea, 'b');
break;
}
});
참고. 그런 다음
:
function simpleReplace(element, wrapper) {
$(element).val(wrapper);
}
은 물론 당신은 또한 루프의 내부 simpleReplace
기능을 넣을 수 있습니다. 이렇게하면 모든 텍스트 영역이 "자신의"simpleReplace
함수가됩니다. 그러나 이것은 또한 메모리 사용량을 증가시킬 것입니다.