当我尝试通过文本表单的元素 Id 作为提交事件访问其输入值时,我的控制台返回空白。但是,提交事件 (控制台.log(e)) 按预期运行。我看了又看,但看不到任何不对劲的地方。我哪里出错了?这是我的代码:let btn = document.getElementById("customer-name-button")let form = document.getElementById("customer-name")form.addEventListener('submit', submitName)btn.addEventListener('click', clearForm)function submitName(e) { e.preventDefault() let customerName = document.getElementById("customer") console.log(customerName.value) console.log(e)}function clearForm() { return form.reset();}<form id="customer-name"> <input type="text" name="customer" id="customer" placeholder="Please tell us your firstname"> <br> <button type="submit" id="customer-name-button">Submit</button></form>
添加回答
举报
0/150
提交
取消