咋用JS 改变P标签中指定字母的颜色
咋用JS改变P标签中指定字母的颜色<pid="p1">Therewasonceaking'ssonwhohadabridewhomhelovedverymuch.</p>...
咋用JS 改变P标签中指定字母的颜色<p id="p1">There was once a king's son who had a bride whom he loved very much.</p>
展开
1个回答
展开全部
//操作鼠标所选择字符
if (document.selection) {
var z = document.selection.createRange();
var t = z.text;
var v = z.htmlText;
z.select();
} else {
var z = window.getSelection().getRangeAt(0);
var t = z.toString();
var temp = document.createElement("span");//a是div的id/a所在当前文件
temp.style.fontSize="red";
temp.innerHTML = t;
z.deleteContents();
z.insertNode(temp);
}
if (document.selection) {
var z = document.selection.createRange();
var t = z.text;
var v = z.htmlText;
z.select();
} else {
var z = window.getSelection().getRangeAt(0);
var t = z.toString();
var temp = document.createElement("span");//a是div的id/a所在当前文件
temp.style.fontSize="red";
temp.innerHTML = t;
z.deleteContents();
z.insertNode(temp);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询