使用JavaScript访问Repeater值 [英] Access Repeater values using JavaScript

查看:80
本文介绍了使用JavaScript访问Repeater值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NET上搜索了很多,以获得解决方案,但我找不到

i searched a lot on NET, to get the solution, but i could not find

任何人都可以告诉我如何访问转发器控件的标签和文本框值在里面使用javascript?

Can anyone tell me how to access the label and textbox values of repeater control inside using the javascript ?

这是我的代码

 <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
    <ItemTemplate>
        <table id="t1" width="200px:" style="background-color: skyblue" runat="server">
            <tr>
                <td>
                    <asp:TextBox ID="TextBox3" Text='<%#DataBinder.Eval(Container.DataItem, "empid")%>'
                        runat="server" />
                    <asp:CheckBox ID="CheckBox1" runat="server" />
                    <asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "empid")%>'></asp:Label>
                    <asp:Label ID="lblname" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "ename")%>'></asp:Label>
                    <br />
                    <br />
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:Repeater>

现在我想使用javascript访问转发器的标签,文本框

Now i want to access the label, textbox of repeater using javascript

@Diodeus

我试过你的代码

function submitAll() {
        var thisLabel = $('.myLabel').eq(0);
        alert(thisLabel);
    }

但我得到了警告的结果

[object Object]

[object Object]

和@deostroll

and @deostroll

我用这种方式尝试了你的代码

I tried your code this way

但没有得到任何东西

    function GetData() {
        var arrTables = document.getElementById('myDiv').getElementsByTagName('table');
        var tbl = arrTables[0];
        var td = tbl.childNodes[0].childNodes[0].childNodes[0];
        var txt = td.childNodes[0];
        alert(txt.value);        
    }


推荐答案

<asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "empid")%>'></asp:Label>

ID必须是唯一的,因此您不能将相同的ID应用于您的所有标签中继器。改为使用CSS类名。

IDs must be unique, so you can't apply the same ID to all of the labels in your repeater. Use CSS class names instead.

<asp:Label CssClass="myLabel" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "empid")%>'></asp:Label>

由于jQuery附带了.NET,因此您可以使用它而不是普通的JavaScript来更轻松地访问这些元素。

Since jQuery comes with .NET you can use it instead of plain JavaScript to access these elements more easily.

var thisLabel = $('。myLabel')。eq(0)其中0是指数元素,因为可以有很多。

var thisLabel = $('.myLabel').eq(0) where 0 is the index of the element since there can be many.

这篇关于使用JavaScript访问Repeater值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆