Thread JS: Frage zur Parameterübergabe mit JSON
(51 answers)
Opened by Kuerbis at 2011-08-26 19:59
Ich habe jetzt versucht an jede Zeile einen Remove-Button anzuhängen, aber die Zuweisung der remove_row Funktion an das input.onclick Attribut funktioniert nicht. Wie macht man so etwas - eine Funktion an ein solches Attribut zuzuweisen?
Code (html): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 <!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <script type="text/javascript"> function ad_row() { var data = { menge : { type : 'number', }, bezeichnung : { type : 'text', }, euro_stueck : { type : 'text', }, count : { type : 'hidden' }, remove : { type : 'button', value : ' - ' }, }; var table = document.getElementById( 'product' ); var rows = table.getElementsByTagName( 'tr' ).length; var tr = table.insertRow( rows ); tr.id = 'tr_' + rows; for ( name in data ) { var td = document.createElement( 'td' ); var input = document.createElement( 'input' ); for ( attr in data[name] ) { input[attr] = data[name][attr]; } if ( name == 'count' ) { input.name = name; input.value = rows; } else if ( name == 'remove' ) { input.onclick = "remove_row('" + tr.id + "')"; } else { input.name = name + '_' + rows; } td.appendChild( input ); tr.appendChild( td ); } } function remove_row( tr_id ) { var this_tr = document.getElementById( tr_id ); var tbody = this_tr.parentNode; tbody.removeChild( this_tr ); } </script> </head> <form> <table id="product"> <tr id="tr_0"><th>Menge</th><th>Bezeichnung</th><th>Euro/Stück</th></tr> <tr id="tr_1"> <td><input type="number" name="menge_1" /></td> <td><input type="text" name="bezeichnung_1" /></td> <td><input type="text" name="euro_stueck_1" /></td> <td><input type="hidden" name="count" value="1" /></td> <td><input type="button" value=" - " onclick="remove_row('tr_1')" /></td> </tr> </table> <br /> <input type="button" value="Eintrag hinzufügen" onclick="ad_row()" /> <br /> <input type="submit" value="OK"/> </form> </body> </html> |