gpt4 book ai didi

javascript - Html 按钮无法与 JavaScript 配合使用

转载 作者:行者123 更新时间:2023-12-02 17:19:12 26 4
gpt4 key购买 nike

我在 PhyCharm 中创建了一个简单的应用程序,在我的 static 文件夹中,我有一个 .js 文件,在我的模板文件夹中,有一个 index.html 文件。

在我的 .js 文件中,我有这个:

console.log('loaded script.js');

$(document).ready(function () {

$("#submit").on('click', function (event) {
handleClick();
});

});

function handleClick() {
alert("We got here");
$.ajax('/', {
type: 'GET',
data: {
fmt: 'json'
}
});
}

这是index.html:

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="static/script.js"></script>
</head>
<body>
<input type="button" id="submit" value="Get It">
</body>
</html>

当应用程序加载时,“loaded script.js” 显示在控制台中,但按钮单击不起作用。我不确定为什么,因为代码对我来说看起来很好。

最佳答案

大家已经给你答案了。这个使用 Google 的 CDN。

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="static/script.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"/>
</head>
<body>
<input type="button" id="submit" value="Get It">
</body>
</html>

引用http://jsfiddle.net/hpX3e/举个例子。

关于javascript - Html 按钮无法与 JavaScript 配合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24125699/

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