为什么click函数在jQuery中不起作用?

-1 jquery click

当我点击div或类"c"时,我正在尝试做某事,但似乎它不起作用.有什么建议我怎么解决它?

<html>

    <head>
        <title>My seconf jQuery practice</title>
        <style>
            .c {
                width: 100px;
                height:100px;
                border-radius: 50px;
                background-color: red;
            }
        </style>
    </head>

    <body>
        <div class="c"></div>
        <p>My text
            <script "type=text/javascript" src="jquery-min.js">
                $(".c").click(function() {
                    //$("p").html("my text has changed");
                    alert('hi');
                });
            </script>
    </body>

</html>
Run Code Online (Sandbox Code Playgroud)

tax*_*ala 5

你的脚本标签有误,应该如下:

<script type="text/javascript"  src="jquery-min.js"></script>
<script type="text/javascript">
    $(".c").click(function() {
        //$("p").html("my text has changed");
        alert('hi');
    });
</script>
Run Code Online (Sandbox Code Playgroud)

如果你得到404,你可能需要在src中添加一个斜杠:

<script type="text/javascript"  src="/jquery-min.js"></script>
Run Code Online (Sandbox Code Playgroud)

请注意,您已经写过"type=text/javascript",应该是type="text/javascript"