0

我正在尝试通过链接显示警告框并使用 jQuery,但似乎我没有做对。

我的链接:

<a class="details_link">Details</a>

我的 jQuery 函数:

$(document).ready(function () {
        $(".details_link").click(function () {

            alert("test");
        });
    })

此代码不起作用...我已经检查了 Stack 上的其他答案,但我认为我已按照说明进行操作。我包括 jquery-1.9.1.js 文件。

4

3 回答 3

2

First check you have the correct jQuery Scripts loaded.

You are missing a few things.

The href attribute is missing from your anchor tag, although this is not what is causing the issue it is bad practice to not include it.

<a href="#"class="details_link">Details</a>

You are also missing a semi colon from your jquery

$(document).ready(function () {
    $(".details_link").click(function () {
        alert("test");
    });
});
于 2013-04-13T16:23:11.867 回答
0

请确保您正确引用了 jquery 库。你的代码对我有用。在这里查看

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

如果你的 jquery 库是正确的并且准备好使用,你也可以去验证

IE 调试器 >> 脚本标记和开始调试 jquery 库旁边的下拉列表中应该出现。

在此处输入图像描述

于 2013-04-13T16:21:22.387 回答
0

我几乎可以保证这不是 jquery click 功能无法正常工作,而是您的代码中的某些内容。

  1. 确保包含 jQuery 库。
  2. 确保您的功能在<script>标签内。
  3. 检查 Web 控制台以查看是否有需要解决的错误。

然后,

$(document).ready(function () {
    console.log('test1');
    $(".details_link").on('click',  function () {
        alert("test2");
    });
    console.log('test3');
});
console.log('test4');

看看这些console.log语句中的哪一个打印出来。

于 2013-04-13T16:23:57.640 回答