<li>
<div id="5" display="block" class="item">
<input type="text" style="border:0; height:24px" disabled="disabled" id="relatedSinoWord" value="水草" class="input_ar_out">
<em onclick="change()" class="close"></em>
</div>
</li><li>
……代码同上
</li><li>
……代码同上
</li>
如何实现点击em标签时隐藏其所在的div(注:每个div的id值是随机的),同时去掉其中input的disabled属性?

解决方案 »

  1.   

    另注:input的id="relatedSinoWord"也是随机的。每个li中均是如此。
      

  2.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>
        <script type="text/javascript">
            function change(){
                var divObj = document.getElementById("5");
                var txtObj = document.getElementById("relatedSinoWord");
                
                //divObj.style.display = "none"; //去掉前面的注释就可以达到你要的效果了。不过加上才好看效果
                alert(txtObj.disabled);
                txtObj.removeAttribute("disabled");
                alert(txtObj.disabled);
            }
        </script>
    </head>
    <body>
    <li>
    <div id="5" display="block" class="item">
    <input type="text" style="border:1px width red; height:24px" disabled="disabled" id="relatedSinoWord" value="水草" class="input_ar_out">
    <em onclick="change()" class="close">爷们</em>
    </div>
    </li>
    </body>
    </html>
      

  3.   

    不明白你的用意, 如果隐藏了, 修改textbox的属性还有何用?
      

  4.   

    修改了一下, 可以应对你所说的:乱七八槽的id都是随机的。
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>
        <script type="text/javascript">
            function change(obj){
                var divObj = obj.parentElement;
                var txtObj = divObj.getElementsByTagName("input")[0];
                
                //divObj.style.display = "none"; //去掉前面的注释就可以达到你要的效果了。不过加上才好看效果
                alert(txtObj.disabled);
                txtObj.removeAttribute("disabled");
                alert(txtObj.disabled);
            }
        </script>
    </head>
    <body>
    <li>
    <div id="5" display="block" class="item">
    <input type="text" style="border:1px width red; height:24px" disabled="disabled" id="relatedSinoWord" value="水草" class="input_ar_out">
    <em onclick="change(this)" class="close">爷们</em>
    </div>
    </li>
    </body>
    </html>
      

  5.   

    我试了一下当打开JS中的alert时候,能够实现隐藏div同时去掉disabled属性,但我注释掉alert时,只能隐藏div不能去掉disabled属性。不知道什么原因?
      

  6.   

    哪里有你所说的情况啊?你先点按钮, 再点“爷们”, 再点按钮, 难道没有变化吗?<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>
        <script type="text/javascript">
            function change(obj){
                var divObj = obj.parentElement;
                var txtObj = divObj.getElementsByTagName("input")[0];
                
                divObj.style.display = "none"; 
                txtObj.removeAttribute("disabled");
            }
            
            function getTxtAttr(){
                var txtObj = document.getElementById("relatedSinoWord");
                alert("txt的disabled状态:" + (txtObj.disabled?"是":"否"));
            }
        </script>
    </head>
    <body>
    <li>
    <div id="5" display="block" class="item">
    <input type="text" style="border:1px width red; height:24px" disabled="disabled" id="relatedSinoWord" value="水草" class="input_ar_out">
    <em onclick="change(this)" class="close">爷们</em>
    </div>
    </li><input type="button" onclick="getTxtAttr()" value="取文本的disabled属性" />
    </body>
    </html>