1 function addVariable() {2 const list = document.getElementById('variables-list');3 const li = document.createElement('li');4 li.classList.add('flex', 'space-x-4', 'items-center');5 li.innerHTML = `6 <input type="text" placeholder="Variable Name" class="flex-1 p-2 border border-gray-300 rounded" />7 <input type="text" placeholder="Variable Value" class="flex-1 p-2 border border-gray-300 rounded" />8 <button type="button" onclick="removeVariable(this)" class="text-red-500">x</button>9 `;10 list.appendChild(li);11 }12 13 function removeVariable(element) {14 element.parentElement.remove();15 }16 17 function saveTest() {18 const variables = [];19 const listItems = document.getElementById('variables-list').children;20 for (let i = 0; i < listItems.length; i++) {21 const name = listItems[i].children[0].value;22 const value = listItems[i].children[1].value;23 if (name && value) {24 variables.push({ name, value });25 }26 }27 console.log('Variables:', variables);28 alert('Test saved!');29 }30
Enlace
El enlace para compartir es: