gpt4 book ai didi

javascript - 将表单文本输入发送到 console.log 进行测试

转载 作者:搜寻专家 更新时间:2023-11-01 05:12:05 24 4
gpt4 key购买 nike

我有一个简单的表单,其中包含一个用于测试的文本字段。我现在需要将用户输入的信息发送到 console.log。这可能吗?如果可以,我会写什么?

<form class="pure-form">
<input id="name" type="text" placeholder="Enter Name" />
<button type="submit"><i class="fa fa-chevron-circle-right"></i></button>
</form>

最佳答案

var nameInput = document.getElementById('name');

document.querySelector('form.pure-form').addEventListener('submit', function (e) {

//prevent the normal submission of the form
e.preventDefault();

console.log(nameInput.value);
});

关于javascript - 将表单文本输入发送到 console.log 进行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21491119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com