2014-05-23 3 views
1

Я как бы новый для JQuery, и сейчас я в очень трудном положении. Мне нужно, чтобы пользователь мог писать в абзаце, а затем изменить цвет текста по своему усмотрению, но только выделенный текст из его абзаца, например, текстовое редактирование в браузере. Вот мои файлы:
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

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

JS

$('#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 ? 
} 

Важная информация : Я не хочу, чтобы весь абзац изменить, только сегмент, выбор, как в текстовых редакторах

+0

Я гугле до http://api.jquery.com/select/. Он говорит> Это событие ограничено '' fields и '