我希望有一个文字,当点击拖动时,突出显示文本并将突出显示的文本存储在变量中。
我不确定从哪里开始,从我的研究看起来它可能与html5和画布有关但我对html5没有太多经验所以非常感谢任何帮助。
答案 0 :(得分:1)
$(document).ready(function() {
$(document).on('click', function() {
var selection = '';
if (window.getSelection) {
selection = window.getSelection().toString();
}
else if (document.selection) {
selection = document.selection.createRange().text;
}
$('.highlighted').append(selection + '<br/>');
});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
aslkdfjasd thiasldfkjljaslkdjf kasjdlfj lkjasdlkfjl ajsdfll kjlasjdfl laskjdfl lkjasldkfjlakjsdfj;lkjlaksdlfkjl lkjasldkfjl asdfkj jasldjflj asdlkfjalskdjf lkkjasdlklfjlasjdlfkjasdkfjl asdlfjsaf
this is some random text
<br/><br/>
The following text was highlighted:<br/>
<div class="highlighted" style="font-weight:bold;"></div>
&#13;