可以尝试使用document.selection.createRange().text把选中文字变为蓝底白字。
解决方案 »
- 请各位大神帮忙看看,代码一样为啥一个可以用一个不能用
- 如何为动态创建的Image对象设置手形.
- 发一个html5开发的坦克大战demo,大家给点建议
- 高分求可以在框架网页下使用的Javascript 日历代码
- 请教问题!!像CSDN的那样点击框架左边页面的控件,而框架右面的页面跳转是怎么做的???
- XPSPII系统IE始终报错
- 简单的问题:如果将text输入栏设置属性为readonly?
- 关于textarea的问题......
- 如何在htm网页中用链接调用HTA页面??
- Ext.js初学者,求好的学习网址
- 超简单问题,form的提交问题,解决了马上给分
- 如何在js 引用合并后的单元格 ??? 急
只是在失去焦点时如Imaly(阿伦)等所说,把字变成了蓝底白字。
具体怎么实现蓝底白字啊?
如果你选中的是网页中的文本,那可以用下面的方法:function highlightWordInText(aWord, textNode){
allText=new String(textNode.data);
allTextLowerCase=allText.toLowerCase();
index=allTextLowerCase.indexOf(aWord);
if(index>=0){
// create a node to replace the textNode so we end up
// not changing number of children of textNode.parent
replacementNode=document.createElement("span");
textNode.parentNode.insertBefore(replacementNode, textNode);
while(index>=0){
before=allText.substring(0,index);
newBefore=document.createTextNode(before);
replacementNode.appendChild(newBefore);
spanNode=document.createElement("span");
if(isSafari){
spanNode.style.color="#000000";
spanNode.style.background="#B5D5FF";
}else{
spanNode.style.background="Highlight";
spanNode.style.color="HighlightText";
}
replacementNode.appendChild(spanNode);
boldText=document.createTextNode(allText.substring(index,index+aWord.length));
spanNode.appendChild(boldText);
allText=allText.substring(index+aWord.length);
allTextLowerCase=allText.toLowerCase();
index=allTextLowerCase.indexOf(aWord);
}
newAfter=document.createTextNode(allText);
replacementNode.appendChild(newAfter);
textNode.parentNode.removeChild(textNode);
}
}