一个页面,有两个DIV,为A和B。B容器,内有两个文本框,初始时B容器的display:none,在一个单击事件后,display转换为block,但是在初始时写的JS,代码就无法获取B容器内的文本框的值。
--------------------
如果display一直为block,则可以取到,求解决方法。
        window.onload = function () {
            $("#btnXWBLMB").click(function () {
                $("#divBLMB").attr("display", "block");
                $("#divLayout").attr("display", "none");
            });
            $("#txtyuanshi").mouseover(function () {
                $(this).addClass("exstyle").mouseout(function () {
                    $(this).removeClass('exstyle');
                });
            });
            $("#putClear").click(function () {
                document.getElementById("txtnew").innerHTML = "";
                $("#txtnew").focus();
            });
            $("#yuanshiDiv").click(function () {
                var str = document.getElementById("txtyuanshi").innerHTML;
                document.getElementById("txtnew").innerHTML = str;
            });
        }

解决方案 »

  1.   


    HTML代码好长。
    ------------第一个容器------------
            <div id="divLayout" class="Layout">
                <div class="HeaderDiv">
                </div>
            </div>
    -----------第二个容器------------
        <div id="divBLMB" style="width: 800px; height: auto; padding-left: 50px;">
            <div style="width: 800px; background-color: #eeffee;">
                <div style="float: left; width: 100%; padding-left: 10px; border: 1 0 #fff; padding-bottom: 10px;">
                    笔录模板分类:<asp:DropDownList ID="ddlBLFL" runat="server" Width="150px">
                    </asp:DropDownList>
                </div>
                <div id="yuanshiDiv" style="height: 500px; float: left; width: 35%; padding-left: 10px;
                    overflow: hidden; border: #000 solid 1px;">
                    <asp:TextBox ID="txtyuanshi" runat="server" Height="500px" TextMode="MultiLine" Width="260px"
                        ReadOnly="true"></asp:TextBox>
                </div>
                <div style="height: 500px; float: right; width: 60%; padding-right: 10px;">
                    <asp:TextBox ID="txtnew" runat="server" Height="500px" TextMode="MultiLine" Width="450px"></asp:TextBox>
                </div>
                <div style="float: left; width: 100%; padding: 0 10 0 10;">
                    <div style="float: right; width: 60%; padding-top: 20px;">
                        <<input type="button" value="确定" />&nbsp;
                        <input id="putClear" type="button" value="清空" />&nbsp; <<input type="button" value="返回" />&nbsp;
                    </div>
                </div>
            </div>
        </div>
      

  2.   

    应该不是display样式引起的,因为不管是否隐藏,总是可以获取到值的。看错误信息吧。
      

  3.   


    找到原因了,
    服务器控件被渲染到页面后,HTML代码变了,这是浏览后的源代码。ID变为ContentPlaceHolder1_txtnew。
    还是很谢谢你。<textarea name="ctl00$ContentPlaceHolder1$txtnew" rows="2" cols="20" id="ContentPlaceHolder1_txtnew" class="asptextbox" style="height:500px;width:450px;">