问题描述
我有一个具有行号和文本的contentEditable iframe.行号包含在div中,所有文本均包含在<pre>
元素中.
I have a contentEditable iframe with line numbers and text. The line numbers are contained in a div and all text is in a <pre>
-element.
它看起来像这样:
<body>
<div id="line_numbers">
<div>1</div><div>2</div><div>3</div>
</div>
<pre>
Text
</pre>
</body>
现在,当有人按Ctrl + A时,将选择所有内容,包括行号.我想将此行为更改为仅包含<pre>
的内容.
Now, when someone presses Ctrl+A everything is selected, including the line numbers. I would like to change this behaviour to only include the contents of the <pre>
.
我已经设置了一个捕获Ctrl + A并阻止默认操作的函数.现在,如何设置选择以包含<pre>
中的所有内容?
I have set up a function that captures Ctrl+A and prevents the default operation. Now, how do I set the selection to contain everything within the <pre>
?
推荐答案
我认为会对您有所帮助;您应该能够使用jQuery选择pre元素并将其传递到提供的函数中:
This answer will help you out I think; you should be able to select the pre element using jQuery and pass it into the function supplied:
SelectText($('pre')[0]);
这篇关于如何选择< pre>中包含的所有文本;使用jQuery吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!