2014-12-29 3 views
1

내가하고 싶은 일은 내 프로젝트에 온라인 북마크 앱을 만들고 싶습니다. HTML 템플릿에서 요소 나 단락 또는 텍스트를 선택하고 템플릿의 선택한 부분에 특정 색상을 할당 한 다음 현재 사용자, 선택한 색상 및 현재 URL 및 다음 번에 데이터베이스에 저장하려는 경우 텍스트를 선택한 사용자가 동일한 페이지를 방문하면 동일한 텍스트가 사용자가 선택한 동일한 색상으로 나타납니다.여러 텍스트에서 선택한 텍스트 찾기

예 : 나는 두 단락에서 Java Script라는 단어를 선택하고 일부 단락이있는 서식 파일을 가지고 있습니다. 단어 자바 스크립트가 반복됩니다.

JavaScript was originally developed by Brendan Eich, while working for Netscape 
Communications Corporation. While competing with Microsoft for user adoption of web 
technologies and platforms, Netscape considered their client-server offering a 
distributed OS with a portable version of Sun Microsystems' Java providing an 
environment in which applets could be run. 

JavaScript was originally developed by Brendan Eich, while working for Netscape 
Communications Corporation. While competing with Microsoft for user adoption of web 
technologies and platforms, Netscape considered their client-server offering a 
distributed OS with a portable version of Sun Microsystems' Java providing an 
environment in which applets could be run. 

JavaScript was originally developed by Brendan Eich, while working for Netscape 
Communications Corporation. While competing with Microsoft for user adoption of web 
technologies and platforms, Netscape considered their client-server offering a 
distributed OS with a portable version of Sun Microsystems' Java providing an 
environment in which applets could be run. 

어떤 언어로 내가 선택한 java script 단어를 찾을 수 있습니까? DOM은 어느 단락에서 단어를 선택했는지와 같은 조작을 제공합니까? 도움을 받으실 수 있습니다

답변

1

선택한 텍스트의 범위를 가져 오는 방법은 this StackOverflow question의 답변을 참조하십시오. 그런 다음 startOffset 및 endOffset Range 속성을 사용하여 선택한 텍스트의 시작 및 끝 인덱스를 데이터베이스에 저장할 수 있으므로 나중에이 텍스트를 다시 선택하고 색이 지정된 배경을 가진 새로운 스타일의 DOM 노드를 만들거나 그런 식으로.

관련 문제