javascript - select dynamically muiltiple element from a html table -
I want to dynamically select the value from the list coming from the database with JavaScript. My table What do I need when I put it on the selection button, I have a warning that shows the value of each TD ID in javascript or jquery & lt; Td>
and & lt; Tr & gt; Dynamically created from a database I manage the "id" attribute with 0, for the loop in front of it. Also like the "ID" of the selection button
& lt; Tr & gt; & Lt; Td id = "pres0" & gt; Bear & lt; / Td> & Lt; Td id = "cod0" & gt; Ddfd & lt; / Td> & Lt; Td id = "id0" & gt; 23 & lt; / Td> & Lt; Td> & Lt; Input type = "button" value = "select" id = "id-but-select0" & gt; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td id = "pres1" & gt; Cat & lt; / Td> & Lt; Td id = "cod1" & gt; Ez & lt; / Td> & Lt; Td id = "id1" & gt; 121 & lt; / Td> & Lt; Td> & Lt; Input type = "button" value = "select" id = "id-but-select1" & gt; & Lt; / Td> & Lt; / TR & gt; & Lt ;! - Total number of databases selected - & gt; & Lt; Input id = "nbra" type = "hidden" value = "2" & gt;
I recommend:
showCellValues (e) {// any default tasks Preventing: e. Stop shock (); // To create a variable to cross the 'this' caching: var self = this, // DOM for later (potential) (to follow the loop): cell = self, // to work Whether to require text content or internal text // // text in a node: textProp = 'textContent' in the document? 'Text Content': 'Internal Text'; // While the cell element is a & lt; Td> No element: while (cell.tagName.toLowerCase ()! == 'TD') {// We assign current parental nodes to cell variables, and then go again: cell = cell.parentNode; } // An empty array to keep the key-value added: var keyValues = []; // Turn the node list of the child elements of the parent node on an array, // array again on that heat. Protopp For pre (): [] .slice.call (cell.parentNode.children, 0) .for eca (function) {// We want to get value from siblings (cell / clicked & lt; If / (if the cell is not current L), then we should: String a string / / key: value push (key.values.push (el.id + ': '+ El [textProp]);}}; // Show output, use a warning, or return or whatever your // requirements: console.log (keyValues.join (', '));} / / Type = buttons * and * value = all of the selections Convert diallist // is within an & lt; td & gt; element in an array, and walk on that array: [] .slice.call (document.querySelectorAll ('td> Input [type ='] "] [Value =" select "] '), 0) .for unit (function (button) {/' click 'event-operator fun binding Ction (showCellValues): button AddEventListener (' click ', Showsellwell) ;});
function showcase (E) {e.preventDefault (); Var self = this, cell = self, textProp = 'text content in document'? 'Text Content': 'Internal Text'; While (cell.tagName.toLowerCase ()! == 'TD') {cell = cell.parentNode; } Var keyValues = []; [] .slice.call (cell.parentNode.children, 0) .for eca (function (l) {if (el! == cell) {keyValues.push (el.id + ':' + el [textProp]) ;}}); Console.log (keyValues.join (',')); } [].]]. ().] () (Proof) (button) (button AddEventListener (click on 'click'., ShowCellValues);});
& lt; table & gt; & lt; tbody & gt; & lt; tr & gt; & lt; td id =" pres0 "& gt; bears & lt; / td & gt; & lt ; Td id = "cod0" & gt; ddfd & lt; / td> & lt; td id = "id0"> 23 & lt; td & gt; & lt; Input type = "button" value = "select" id = "id-but-select0" /> gt; & gt; & gt; & lt; / TR & gt; & lt; tr & gt; ; Td id = "pres1" & gt; CAT & lt; / td> & lt; td id = "cod1"> Az & lt; td id = "id1" & amp; Gt; 121 & lt; / td> & lt; td & gt; & lt; input type = "button" value = "select" id = "id-but-select1" /> & gt; & lt; / TD & gt; & lt; / TR & gt; & lt; / tbody & gt; & lt; / table & gt;
Reference:
- . *.
- .
- .
- .
Comments
Post a Comment