如何选择< pre>中包含的所有文本;使用jQuery吗? [英] How do I select all text contained in <pre> using jQuery?

查看:157
本文介绍了如何选择< pre>中包含的所有文本;使用jQuery吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有行号和文本的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>?

推荐答案

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]);

这篇关于如何选择&lt; pre&gt;中包含的所有文本;使用jQuery吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆