개발자
자바스크립트로 텍스트에디터 만들고 있는데, 정작 글을 수정하려고 하면 텍스트에디터가 실행이 안되어요. 예를 들어 볼드체 버튼을 만들었고, 글을 수정하는 페이지에서 볼드체 버튼을 눌렀는데, 누르는 것이 안되는.. html 데이터 전체를 다른 파일에 옮겨서 저장하는 방식이고 수정할 때에는 그 파일을 조회해서 가져오는 형식인데, 그래서 텍스트 에디터는 아예 끼지도 않았거든요.. 썸머노트 등 텍스트 에디터를 꼈을 때에는 수정하고 저장하기 누를 때마다 에디터가 한 개씩 더 생기는 상황입니다. 질문이 좀 추상적이긴 한데 어느 부분에 문제가 있을까요?
답변 2
익명
작성자
2023년 02월 06일
//볼드체 자바스크립트 코드 const btnBold = document.getElementById('btn-bold'); btnBold.addEventListener('click', function () { setStyle('bold'); }); //색상 jsp 코드 <div class="editor-menu"> <select id="select-font-color"> <option value="">폰트 색상</option> <option value="#000000">검정</option> <option value="#F03E3E">빨강</option> <option value="#1971C2">파랑</option> </select> //색상 자바스크립트 코드 const selectFontColor = document.getElementById('select-font-color'); selectFontColor.addEventListener('change', function () { setFontColor(this.value); }); function setFontColor(color) { document.execCommand('foreColor', false, color); focusEditor(); } function reportFont() { if (containerEl) { const fontColor = getComputedStyleProperty(containerEl, 'color'); fontColorSelector.value = rgbToHex(fontColor).toUpperCase(); function componentToHex(c) { const hex = parseInt(c).toString(16); console.log(hex); return hex.length == 1 ? '0' + hex : hex; } function rgbToHex(color) { // rgb(r, g, b)에서 색상값만 뽑아 내기 위해서 rgb() 제거 const temp = color.replace(/[^0-9,]/g, ''); // r,g,b만 남은 값을 ,로 [r,g,b] 배열로 변환 const rgb = temp.split(','); return '#' + componentToHex(rgb[0]) + componentToHex(rgb[1]) + componentToHex(rgb[2]); } } 입니다. 블로그에 올려주신 누군가의 코드를 참고한 내용인데, 색상과 볼드체가 동시에 적용도 안 되고, 수정 화면에서도 클릭할 수가 없어서요..!
지금 가입하면 모든 질문의 답변을 볼 수 있어요!
현직자들의 명쾌한 답변을 얻을 수 있어요.
이미 회원이신가요?
지금 가입하면 모든 질문의 답변을 볼 수 있어요!