js替换选中的文字
2024-10-16 19:49:18
替换html中选中的文字
function replaceSelection() {
if (window.getSelection) {
var selecter = window.getSelection();
var selectStr = selecter.toString();
if (selectStr.trim != "") {
var rang = selecter.getRangeAt(0);
var temp = $("<b>" + selectStr + "<b/>");
rang.surroundContents(temp[0]);
}
} else if (document.selection) {//ie
var selecter = document.selection.createRange();
selecter.select();
var selectStr = selecter.text;
selecter.pasteHTML("<b>" + selectStr + "<b/>");
}
}
程序员的基础教程:菜鸟程序员
最新文章
- Making the Grade(POJ3666)
- struts2 action配置时 method 省略不写 默认执行方法是父类ActionSuppot中的execute()方法
- (转)UVM内容梗概
- Learning JavaScript Design Patterns The Singleton Pattern
- Checking Network Configuration requirements Failed
- mysql导出表结构
- tensorflow初探
- 禁用了传说中的PHP危险函数之后,Laravel的定时任务不能执行了?
- Javascript初识之流程控制、函数和内置对象
- 我在Python学习中遇到的问题一
- JAVA核心技术I---JAVA基础知识(类的继承)
- JavaScript术语:shim 和 polyfill
- 1.4 Chrome浏览器
- hook进程
- 使用静态库的一些问题 -all_load
- CNN-利用1*1进行降维和升维
- Android——初学
- Dijkstra 调度场算法 Python实现 一
- nginx高性能WEB服务器系列之六--nginx负载均衡配置+健康检查
- 《从零开始学Swift》学习笔记(Day 24)——枚举