javascript取消文本选定的实现代码
时间:2021-04-21 09:39:27|栏目:JavaScript代码|点击: 次
javascript选定文本取消, 能兼容所有主流浏览器了:
if (document.selection) {
document.selection.empty();
} else if (window.getSelection) {
window.getSelection().removeAllRanges();
}
对于文本框(input,textarea)中的文本选定取消, 这种方法会有一些问题.
不过也有办法, 记录下文本框中的value,再清空,再重新赋值. 方法有点搓, 不过能兼容所有浏览器.
复制代码 代码如下:
if (document.selection) {
document.selection.empty();
} else if (window.getSelection) {
window.getSelection().removeAllRanges();
}
对于文本框(input,textarea)中的文本选定取消, 这种方法会有一些问题.
不过也有办法, 记录下文本框中的value,再清空,再重新赋值. 方法有点搓, 不过能兼容所有浏览器.






