2014-05-23 2 views
1

저는 JQuery를 처음 접했습니다. 지금 당장은 매우 어려운 위치에 있습니다. 사용자가 원하는 단락을 작성하고 브라우저에서 텍스트 편집과 같이 원하는 단락의 텍스트 만 변경할 수 있도록해야합니다.단락 선택 스타일 변경

$('#redText').click(function() { 
    change_color('red'); 
}); 


$('#blueText').click(function() { 
    change_color('blue'); 
}); 

function change_color(theColor) { 
    //What should I put here to make any selected text change the color ? 
} 

중요 정보

.par { 
    width: 300px; 
    height: 300px; 
    border: 2px solid #A3A3A3 
} 

JS
HTML

<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-5589-1" /> 
    <link rel="stylesheet" href="style_ext.css"> 
    <title>Editable Paragraph</title> 
    </head> 
    <body> 
    <p contenteditable="true" class="par" id="txt">This is an editable paragraph.</p> 
    <center> 
      <button type="button" id="redText">Color text in red</button> 
    </center> 
    <center> 
      <button type="button" id="blueText">Color text in blue</button> 
    </center> 
      <script type="text/javascript" src="js/jquery.js"></script> 
      <script type="text/javascript" src="js/pushred.js"></script> 
    </body> 
</html> 

CSS : 여기 내 파일입니다 : 난, 전체 단락 변경 내가 http://api.jquery.com/select/을 봤

+0

텍스트 편집기처럼 만 세그먼트 선택을하지 않습니다. 그것은>이 이벤트는''필드와'