我有一个 addButton 并且在点击事件之后这个按钮转换为输入元素。 我的想法是:用户输入一些东西,我将它存储在一个变量中。但它不起作用。点击按钮后没有提示
$scope.returnText = function (){
let userInput = document.getElementById("userInput").value;
alert(userInput);
}
这是我创建输入的代码:
$scope.add = function() {
const card = document.querySelector(".card");
const addButton = document.getElementById('addButton');
addButton.remove();
const label = document.createElement('form');
card.prepend(label);
label.classList.add("label");
const input = document.createElement('input');
label.prepend(input);
input.setAttribute("type","text");
input.setAttribute("id","userInput");
const enterButton = document.createElement('button');
enterButton.classList.add('enter-btn');
enterButton.innerText = "Go!";
label.append(enterButton);
enterButton.setAttribute("ng-click","returnText()");
}
我尝试用页面上已经存在的元素做同样的事情,它确实有效。我只是无法得到它。