gpt4 book ai didi

javascript - jQuery 未绑定(bind)到表单,

转载 作者:行者123 更新时间:2023-11-28 18:32:27 24 4
gpt4 key购买 nike

我在使用以下代码时遇到问题,

提交按钮未绑定(bind)到 jQuery 脚本,并且控制台未打印任何内容。我不知道问题出在哪里..

<html>

<head>
<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.2.min.js"></script>
</head>

<body>

<script>
// Variable to hold request
var request;

// Bind to the submit event of our form
$("#show").submit(function(event){

console.log ("Im here");

});

</script>
<!--form action="getVehiclePosition.php" method="GET"-->
<!--Name: <input type="text" name="name"><br>-->
<form id="show">
<input type="submit" value="Send">
</form>

</body>
</html>

最佳答案

您的代码无法正常工作,因为在解释和执行脚本时,DOM 中不存在该表单。将您的代码包装在 document-ready 中处理程序。

Specify a function to execute when the DOM is fully loaded.

使用

 $(function () {
//Your code
})
<小时/>

或者,您可以将 script 标记放置在 form 元素下方

关于javascript - jQuery 未绑定(bind)到表单,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37723199/

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