可以尝试使用document.selection.createRange().text把选中文字变为蓝底白字。

解决方案 »

  1.   

    比如在dreamwerver编辑网页时,可以为选中的字体添加超级连接,那dreamweaver不是也做到了吗?
      

  2.   

    我觉得可以选中字体后,如果要在输入框中打字,那可以先用document.selection.createRange().text把选中文字变为蓝底白字,同时记录下焦点所在位子,在将焦点移到输入框中,当文字输入完成以后,再将焦点移到原先变为蓝底白字的文字上,将文字颜色改回来~~
      

  3.   

    那dreamweaver中,为选中字体添加超级连接时,那种效果挺好的,有谁了解啊
      

  4.   

    dreamweaver实现的方法可能就是我说的那种原理吧,嘎嘎
    只是在失去焦点时如Imaly(阿伦)等所说,把字变成了蓝底白字。
      

  5.   

    document.selection.createRange().text
    具体怎么实现蓝底白字啊?
      

  6.   

    document.selection.createRange().text是针对textarea中文字的~具体怎么弄我忘了~看看msdn吧~
    如果你选中的是网页中的文本,那可以用下面的方法: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);
    }
    }