<script>
function fun(){
var str=document.all.myname.outerHTML;
document.all.myname.setAttribute("disabled",true);
}
</script>

解决方案 »

  1.   

    document.all.myname.outerHTML=str.replace(/\<TD/g, "<TD disabled=true")
      

  2.   

    <td id=myname disabled="true">,只能用IE5.5+,。而且要win32平台
      

  3.   

    你这种用法和document.all.myname.disabled=true是一样效果
    在IE5中不能被执行,它还是被写成<td id=myname disabled="true">
    气人
      

  4.   

    to  net_lover(孟子E章) :
    对的呀,老兄你说得很对,只能用于5。5以上的
    可是在5。0的时候如何解决这个问题,
    我看到用<td disabled></td>这样有效
    如何实现把那个多余的东西去掉
      

  5.   

    The outerHTML property is read-only on the HTML, HEAD, BODY, FRAMESET, TBODY, TD, TFOOT, TH, THEAD, and TR objects.
      

  6.   

    document.all.myname.outerHTML = "<TD disabled "+str.substr(3);
    试试吧,应该可以的,outerHTML前三个字符一定是<TD
      

  7.   

    <td id=myname disabled="true">

    <td id=myname disabled=true>
    作用一样
      

  8.   

    <input type=button value="添加"  onclick="fun()">
    <table border=1>
    <tr >
    <td id=myname>快看我</td>
    </tr>
    </table>
    <script>
    function fun(){
    var str=document.all.myname.outerHTML;
    document.all.myname.disabled=true
    }
    </script>
      

  9.   

    不一样的效果,在IE5.0上与IE5.5上这两句差异
    <td id=myname disabled="true">

    <td id=myname disabled>后者成立,前者不成立
      

  10.   

    <script>
    function fun(){
    document.write("......<td id=myname disabled>.....</table>")
    }
    </script>
      

  11.   

    <input type=button value="添加"  onclick="fun()">
    <table border=1>
    <tr id=myname1 disabled style="display:none">
    <td>快看我</td>
    </tr>
    <tr>
    <td id=myname style="display:">快看我</td>
    </tr>
    </table>
    <script>
    function fun(){
    document.all.myname1.style.display=''
    document.all.myname.style.display='none'
    }
    </script>
      

  12.   

    对于ie5,可以用mergeAttributes解决<input type=button value="添加"  onclick="fun()">
    <table border>
    <tr >
    <td id=myname>快看我</td>
    </tr>
    </table><script>
    function fun(){
    myname.mergeAttributes(document.createElement("<TD disabled>"))
    }
    </script>
      

  13.   

    IE5下面的另一种方法:<BODY>
    <input type=button value="添加"  onclick="fun()">
    <table border=1>
    <tr >
    <td id=myname>快看我</td>
    </tr>
    </table><script>
    function fun(){
    var elm=document.all.myname;
    var elm2 = document.createElement("<td disabled></td>")
    elm2.innerHTML = elm.innerHTML
    elm.replaceNode(elm2)
    }
    </script></BODY>
      

  14.   

    to: emu_ston(emu) 但是,你的这种方法 document.all.myname的所有属性都丢失了比如
    <table border=1>
    <tr >
    <td id=myname class="abc" align="left" width="100" nowrap>快看我</td>
    </tr>
    </table>那么。你的处理后.下面的属性
    class="abc" align="left" width="100" nowrap
    都丢失了
      

  15.   

    多谢各位兄弟的帮助
    我的QQ:2469284
    MSN:[email protected]可以相互交流我目前是用net_lover(孟子E章) 的方法解决
    即<script>
    function fun(){
    document.write("......<td id=myname disabled>.....</table>")
    }
    </script>
    重新赋值来解决的,我觉得不太好,因为我是一个大的TABLE的,我待会试下 Go_Rush(阿舜) 的mergeAttributes方法来试试,觉得应该是可以,在IE6上是没问题,下午去MM机子试试,多谢大家啦,
      

  16.   

    Go_Rush(阿舜):
    你的方法比我的好,我只是随便提一下其他的途径而已 :-)
      

  17.   

    myname.mergeAttributes(document.createElement("<TD disabled>"))这样可以 disabled 掉.↑
    这样又无法恢复? ↓myname.mergeAttributes(document.createElement("<TD>"))
      

  18.   

    显然 mergeAttributes是两个element之间合并属性,不会删除以前的属性。要恢复的话,可以这样用 removeAttribute:myname.mergeAttributes(document.createElement("<TD disabled>"))
    alert(myname.outerHTML) 
    myname.removeAttribute("disabled") 
    alert(myname.outerHTML)
      

  19.   

    不行,
    TO  Go_Rush(阿舜) :
    用REMOVE的方法在IE5上通不过,在IE6上没有问题,
    我试了mergeAttributes这个属性,可以让元素失效,但正如前面的兄台所说,没法返回原来的有效状态用REMOVEATTRIBUTE的方法只在IE5以上版本才有用,
    不知道还有其他的方法操作没有?
      

  20.   

    有啊,不过还是得用我的方法:<BODY>
    <input type=button value="disable"  onclick="disable()">
    <input type=button value="enable"  onclick="enable()">
    <table border=1>
    <tr >
    <td id=myname bgcolor=yellow>&iquest;ì&iquest;&acute;&Icirc;&Ograve;</td>
    </tr>
    </table><script>
    function disable(){
    var elm=document.all.myname;
    var elm2 = document.createElement(elm.outerHTML.match(/<td[^>]*>/i).toString().replace(/td/i,"td disabled"));
    elm2.innerHTML = elm.innerHTML
    elm.replaceNode(elm2)
    }
    function enable(){
    var elm=document.all.myname;
    var elm2 = document.createElement(elm.outerHTML.match(/<td[^>]*>/i).toString().replace(/ disabled/i,""));
    elm2.innerHTML = elm.innerHTML
    elm.replaceNode(elm2)
    }
    </script></BODY>
      

  21.   

    讨厌,又是中文乱码。
    <BODY>
    <input type=button value="disable"  onclick="disable()">
    <input type=button value="enable"  onclick="enable()">
    <table border=1>
    <tr >
    <td id=myname bgcolor=yellow>快看我</td>
    </tr>
    </table><script>
    function disable(){
    var elm=document.all.myname;
    var elm2 = document.createElement(elm.outerHTML.match(/<td[^>]*>/i).toString().replace(/td/i,"td disabled"));
    elm2.innerHTML = elm.innerHTML
    elm.replaceNode(elm2)
    }
    function enable(){
    var elm=document.all.myname;
    var elm2 = document.createElement(elm.outerHTML.match(/<td[^>]*>/i).toString().replace(/ disabled/i,""));
    elm2.innerHTML = elm.innerHTML
    elm.replaceNode(elm2)
    }
    </script></BODY>
      

  22.   

    ie 5.0通过:disable用 mergeAttributes
    还原为enable用 clearAttributes
    <input type=button value="add"  onclick="add()">
    <input type=button value="reset"  onclick="reset()">
    <table border>
    <tr>
    <td id=myname>myname<input></td>
    </tr>
    </table><script>
    function add(){
    myname.mergeAttributes(document.createElement("<TD disabled>"))
    }
    function reset(){
    myname.clearAttributes("disabled") 
    }
    </script>
      

  23.   

    :)
    我上班不带手册,瞎写的,Go_Rush(阿舜)的是正解。
      

  24.   

    Go_Rush(阿舜):
    在IE6通不过!
    myname.clearAttributes("disabled") =myname.clearAttributes() 一样的把所有属性清空了
      

  25.   

    哎,其实我也没有手册。
    只是在vi里面写代码的时候出现了 clearAttributes方法。
    我就用了,简单测试了一下见达到目的就贴上来了。现在才知道,他是清空所有属性,而且我的用法还不标准。
    刚才查了一下msdnclearAttributes Method
    --------------------------------------------------------------------------------
    Removes all attributes and values from the object.Syntaxobject.clearAttributes()
    Return ValueNo return value.ResThe clearAttributes method clears only persistent HTML attributes. The ID attribute, styles, and script-only properties are not affected.
    还是emu_ston(emu) 的方法正解阿
      

  26.   

    得,干脆把mergeAttributes方法用script重新实现过算了 :)刚又发现IE的新毛病:<select onfocus="alert(options[2])">
    <option>test</option>
    </select><select onfocus="alert(options[-1])">
    <option>test</option>
    </select>第二个竟然有错!而这样又没错:
    var a=[1];
    alert(a[1])
    alert(a[-1])控件集合的实现看来和数组真的很不同
      

  27.   

    我用emu_ston(emu)的方法解决问题
    就是那个REPLACE的法子,比用代码直接写要方便些,通用些,好啦,散分