将表单文本输入发送到console.log进行测试 [英] Sending form text input to console.log for testing
本文介绍了将表单文本输入发送到console.log进行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有一个文本字段的简单表格,用于测试.我现在需要将用户输入的信息发送到console.log.这可能吗,如果可以的话我会写些什么?
I have a simple form with one text field for testing. I need to have the info the user types in sent to console.log for now. Is this possible and if so what would I write?
<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);
});
这篇关于将表单文本输入发送到console.log进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文