我正在尝试使用ajax,但当我单击按钮时它不起作用,它不会在浏览器上显示警报框。
<html>
<head>
<title>Ajax</title>
<script scr="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
Name: <input type="text" id="data">
<input type="submit" id="sub" value="save">
<script>
$(document).ready(function () {
$('#sub').click(function () {
alert('ok');
});
});
</script>
</body>
</html>
最佳答案
请尝试以下代码
<html>
<head>
<title>Ajax</title>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function(){
$('#sub').click(function(){
alert('ok');
});
});
</script>
</head>
<body>
Name: <input type="text" id="data" >
<input type="submit" id="sub" value="save">
</body>
</html>
1. jquery路径问题 2. 始终将脚本放在 head 部分
关于javascript - 无法访问jquery和ajax的功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35347367/