sel = document.selection;
rng = sel.createRange();
if ( sel.type == "control" )
    if(rng && rng.length>0)
        obj = rng[0];if( obj.tagName.toLowerCase() == "img" )
    obj.style.position = "relative";

解决方案 »

  1.   

    sel = document.selection;
    rng = sel.createRange();
    if ( sel.type == "control" )
        if(rng && rng.length>0)
            obj = rng[0];if( obj.tagName.toLowerCase() == "img" )
        obj.style.position = "relative";楼上的强
      
    http://community.csdn.net/Expert/topic/3774/3774789.xml?temp=.9775965
      

  2.   

    错了
    rng[0]改成rng.item(0)或rng(0)都可以,
    不太明白这个地方.集合为什么会不能像数组一样访问,其它的都可以
      

  3.   

    ice_berg16(寻梦的稻草人)我的上一个问题就是你给我解答的,我的这个问题就是接上个问题来的,在这里谢谢你了,同样感谢zhaoxiaoyang(梅雪香@hisoft) ( ) 另外我想问一下sel.type == "control"是什么意思?我这样做了一下,我按照你上次的方法定义了一个函数,使我选中的文字可以套上div,然后指定style
    function setFont()
    {
    rng = mEditor.document.selection.createRange();
    if(rng.htmlText.length == 0 ) return;
    rng.pasteHTML("<div style='position:absolute;color:red;'>"+rng.htmlText+"</div>");
    }现在的问题是当我选中加上div的文字后,这段文字是可以编辑的,那么我就在这段文字(文字选区被选中)中添加了图片,可是当我第二次选取图片时为什么
    sel = document.selection;
    rng = sel.createRange();
    if ( sel.type == "control" ),中的 sel.type 为none呢?我不太明白control是什么,为什么选取文字选取的图片,这个图片的type为none
      

  4.   

    十分感谢ice_berg16(寻梦的稻草人)我现在没分了,以后有分时一定给你
      

  5.   

    补充一下,上面的文体我可能没有描述清楚:现在在我的编辑区内,我选定了一段文字,这段文字是<div style="position:absolute;">aaddggff</div>,现在我在这段文字上加图片<DIV style=" POSITION: absolute;">aaddg<IMG style="POSITION: absolute;" src= _0.jpg> 
    <DIV></DIV>gff&nbsp;</DIV>但是当我选取图片,想改变图片的style时为什么
    sel = document.selection;
    rng = sel.createRange();
    if ( sel.type == "control" )    sel.type为空了呢?
      

  6.   

    另外我想问一下sel.type == "control"是什么意思?
    不好意思:写的时候笔误了 应该是sel.type == "Control"
    ducment.selection代表文档中你选中的部分,而type表示选择部分的类型,只有三个选项none,Text,Control
    除了选择控件(Control)之外,一般都是Text,不选择为none
      

  7.   

    但是我出现了这样的一个问题就是  当我把图片加到,一个div括起的文字中时,为什么选择img时,
    sel = document.selection;
    rng = sel.createRange();这两句都不好用了,也就是我获得不了img对象,不知道为什么<DIV style=" POSITION: absolute;">文字1<IMG style="POSITION: absolute;" src= _0.jpg> 
    文字2</DIV>