[英]Creating button that axios.post something from input
I have to create a button that will do an axios.post request, if something is in the input.如果输入中有内容,我必须创建一个按钮来执行 axios.post 请求。 Im stuck, my HTML:
我卡住了,我的 HTML:
<!DOCTYPE html>
<html lang="pl-PL">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="HandheldFriendly" content="true">
<title>zad2</title>
</head>
<body>
<input id="newInput" data-test="todo-input" placeholder="wpisz tekst"><button id="newButton" data-test="todo-add" onClick="addToDoElem()">Dodaj</button>
</body>
</html>
And my js:还有我的js:
const $newTask;
let $newInput = document.getElementById('.newInput');
let $newButton;
function addToDoElem() {
if ($newInput.value !== '') {
axios.post(
$newTask = $newInput.value;
)
}
}
Appreciate any tips.感谢任何提示。 Have a nice day!
祝你今天过得愉快!
Just change document.getElementById('.newInput');
只需更改
document.getElementById('.newInput');
by document.getElementById('#newInput');
通过
document.getElementById('#newInput');
, getElementById()
gets DOM element by his id, not his class. ,
getElementById()
通过他的 id 获取 DOM 元素,而不是他的 class。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.