Access Repeater values using JavaScript

前端 未结 2 1945
执笔经年
执笔经年 2021-01-16 12:52

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

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

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-16 13:16

    Wrap the repeater in a div with some id, say myDiv.

    ...

    Do a

    var arrTables = document.getElementById('myDiv').getElementsByTagName('table');
    

    Now arrTables is just array of all table elements inside the div. Find the ordinal of the desired table: For e.g. sake I am taking first table.

    var tbl = arrTables[0];
    

    Find the corresponding td of the table element:

    var td = tbl.childNodes[0].childNodes[0].childNodes[0];
    

    The above may vary based on how your browser loads the DOM and stuff. Hence I say you debug and find out for your self.

    Once you get the td reference:

    var txt = td.childNodes[0];
    

    This will give the textbox. txt.nextSibling will give the label...and so on.

提交回复
热议问题