开发者

Selecting control by ID in JS when ASP.net returns only the name

I am using ASP.net and IE8. I'm trying to select an HTML element using document.getElementById() in JavaScript by passing it a control's ClientID property.

The problem is that the ClientID property returns the 'name' and not the 'id'. IE8 is strict about document.getElementById() only selecting i开发者_开发百科d's and not names.

So how do I get around this?


Can't you refer to the name of the element with getElementsByName()

Maybe this will help.


The following code works fine IE8. Can you elaborate more about your problem? What is the control your using?

<asp:TextBox ID="txtCategory" runat="server"></asp:TextBox>
    <script>
        function ShowValue() {
            alert(document.getElementById('<%=txtCategory.ClientID %>').value); ;
        }
    </script>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="ShowValue()" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜