【发布时间】:2016-09-09 04:19:16
【问题描述】:
我有一个代码,用于单击选择所有文本。但不幸的是不能在 IE 上工作。谁能解决这个问题。
需要修复所有兼容的浏览器。
此脚本在 IE 9.0 以下运行。不适用于 IE 10 及更高版本。所以请给出解决方案。
代码:
<!DOCTYPE html>
<html>
<head>
<title>autoresizing textarea</title>
<style type="text/css">
#divid {
display:inline-block;
border: solid 1px #000;
min-height: 20px;
width: 300px;
}
</style>
<script type="text/javascript">
function selectText(containerid) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select();
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
}
}
</script>
</head>
<body>
<div id="divid" onclick="selectText('divid')">Lorem Ipsum is simply dummy text of the printing and typesetting industry. </div>
<div>
Lorem Ipsum is simply dummy text </div>
</body>
</html>
【问题讨论】:
-
@LouysPatriceBessette 可能确实包含答案,但它不是重复的。它看起来与这个问题相反......
-
@T J 嗯。你说得对。我评论太快了。
-
@user3859368...您只想在点击时选择所有文本,还是想对用户手动选择的文本执行某些操作?
-
@LouysPatriceBessette 是的。它只是重复的。但是这个脚本在 IE 9.0 以下运行。不适用于 IE 10 及更高版本。请为此提供解决方案
标签: javascript css