【发布时间】:2017-02-17 05:05:30
【问题描述】:
设法从 textarea 中获取突出显示的文本并将其传输到另一个 textarea。但是,当编辑代码以便从 div 中获取突出显示的文本时,它就不起作用了......
任何想法为什么会发生这种情况?谢谢。
<div id="quote"> load transcript in here instead and grab text from here</div> // does not work
<textarea id="quote" readonly> // works
load transcript in here
</textarea>
<textarea contenteditable="false" id="output" name="selected"></textarea> // outputs highlighted text here
<script>
var quotearea = document.getElementById('quote')
var output = document.getElementById('output')
quotearea.addEventListener('mouseup', function(){
if (this.selectionStart != this.selectionEnd){ // check the user has selected some text inside field
var selectedtext = this.value.substring(this.selectionStart, this.selectionEnd)
output.innerHTML = selectedtext
}
}, false)
</script>
小提琴:
【问题讨论】:
-
你可以为它做小提琴吗
-
这可能会给你你需要的东西:stackoverflow.com/questions/19288700/…
-
添加了一个小提琴,现在检查那个链接,看起来很相关!干杯。
-
杰拉尔多有效!!谢谢你。有了这个更新的小提琴:jsfiddle.net/eLwy4eLp/1
标签: javascript