โปรเจ็กส์ Web Application เรียกใช้ jQuery

1.อ้างถึง jQuery

ไฟล์ Pages|Shared|_Layout.cshtml

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - WebApp1</title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/css/site.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
...

2.ทดลองใช้งาน เมื่อคลิกที่ <P> แล้วจะแสดง alert

ไฟล์ Pages|Index.cshtml

@page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}

<div class="text-center">
    <h1 class="display-4">Welcome</h1>
    <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>

    <p>Click on this paragraph.</p>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        $("p").click(function () {
            alert("The paragraph was clicked.");
        });
    });
</script>

Link