无法访问 jquery 和 ajax 的功能

Cannot access the function of jquery and ajax

本文关键字:ajax 功能 jquery 访问      更新时间:2023-09-26

我正在尝试使用 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.始终将脚本放在头部部分