javascript - 选择一个div的所有内容

标签 javascript jquery google-chrome select

我在选择 div 的所有内容时遇到问题。这是一个演示:

http://jsfiddle.net/KcX6A/304/

它只选择文本的第一行,其他行被忽略。我该如何解决这个问题?

编辑:

浏览器是google chrome

第二次编辑:

太糟糕了,我会回答我自己的问题。但是我已经让它在 Google Chrome 上工作了:

我已经替换了

selection.setBaseAndExtent(text, 0, text, 1); 

selection.selectAllChildren(text);

它就像一个魅力!如果它也适用于其他浏览器,请告诉我。

Working Demo

最佳答案

似乎删除 webkit 特定调用 setBaseAndExtent 修复了最新 Chrome 中的问题

http://jsfiddle.net/KcX6A/309/

关于javascript - 选择一个div的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8802857/

相关文章:

javascript - yii2 从 View 和调试进程中调用 Controller 操作

javascript - jQuery Unobtrusive验证的验证摘要未显示

javascript - 使用 Javascript (MVC) 在按钮单击时将特定 div contenteditable 设置为 true

c# - 流式视频(C#使用FFmpeg AutoGen)发送多个数据请求

javascript - Google 开始使用 Dart 了吗?他们是否为 Dart 编译器构建了一个 Closure(或 GWT)?

javascript - 如何在 JavaScript 中设置 textBox.Text=radCombo.Text

javascript - 将参数传递给 AngularJS 模板内的函数

mysql - 使用 AJAX 更新数据库

javascript - 单击 popup.html(chrome 扩展)后执行脚本

python - 使用 Selenium 打开 Splinter 浏览器