function javascript가있는 입력 dropdown 필드 추가 및 제거가 제대로...

function javascript가있는 입력 dropdown 필드 추가 및 제거가 제대로...

var i = 1 ; $ ( '#AddItemOption .btn-default' ). on ( 'click' , function ( e ) { i ++; var el = $ ( '.table-additems tbody tr:eq(0)' ). clone (); $ ( el ). find ( 'option:selected' ). removeAttr ( 'selected' ); $ ( el ). find ( ':input' ). each ( function () { $ ( this ). removeAttr ( 'value' ); }); //while cloning hide other input $ ( el ). find ( '.inputother' ). css ({ 'display' : 'none' }); $ ( this ). closest ( 'tr' ). before ( '' + $ ( el ). html () + '' ); }); $ ( document ). on ( 'click' , '#AddItemOption .btn-danger' , function ( e ) { if ( $ ( '.table-additems tbody tr' ). length == 2 ) { var el = $ ( '.table-additems tbody tr:eq(0)' ); $ ( el ). find ( 'select:eq(0)' ). val ( $ ( el ). find ( 'select:eq(0) option:first' ). val ()); $ ( el ). find ( 'select:eq(1)' ). val ( $ ( el ). find ( 'select:eq(1) option:first' ). val ()); $ ( el ). find ( 'input:eq(0)' ). val ( '' ); e . preventDefault (); } else { $ ( this ). closest ( 'tr' ). remove (); } }); //use this because other slect-box are dynmically created $ ( document ). on ( 'change' , '.sellitem' , function ( e ) { if ( $ ( this ). val () == 'other' ) { //find this ->closest trs-> get input box show $ ( this ). closest ( "tr" ). find ( '.inputother' ). css ({ 'display' : 'block' }); } else { $ ( this ). closest ( "tr" ). find ( '.inputother' ). css ({ 'display' : 'none' }); } });

repl.it items Delete book pencil pen other Delete + Add New Item

from http://qastack.tistory.com/70 by ccl(A) rewrite - 2021-10-27 21:26:17