Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
单击链接时不调用jquery函数_Jquery_Html - Fatal编程技术网

单击链接时不调用jquery函数

单击链接时不调用jquery函数,jquery,html,Jquery,Html,我试图在单击链接时调用jquery函数,但它不起作用,根本不调用该函数 功能: <script> $(document).ready(function () { $('#notif').click(function () { var id = $(this).attr("data-id"); alert('test'); $.ajax({

我试图在单击链接时调用jquery函数,但它不起作用,根本不调用该函数

功能:

<script>
    $(document).ready(function () {

        $('#notif').click(function () {
            var id = $(this).attr("data-id");
                        alert('test');
            $.ajax({
                type: "POST",
                url: "inc/showNotif.php",
                dataType: "html",
                data: {
                    id: id
                },
                success: function (result) {
                    $('.displayNotif').html(result);
                    console.log(result)
                }
            });

        });
    });
    </script>

$(文档).ready(函数(){
$('#notif')。单击(函数(){
var id=$(this.attr(“数据id”);
警报(“测试”);
$.ajax({
类型:“POST”,
url:“inc/showNotif.php”,
数据类型:“html”,
数据:{
id:id
},
成功:功能(结果){
$('.displayNotif').html(结果);
console.log(结果)
}
});
});
});
链接:


编辑 我发现标记之间的代码根本不会执行,即使删除onclick事件也不会执行

编辑2 问题是
$(document).ready(function()
没有它的代码可以工作,但是为什么呢

解决了的
问题是一些jquery错误阻止了文档。rady

您好,我想可以帮助您!!只需删除href=“#”或停止事件传播您还可以将
href=“#”替换为
href=“javascript:void(0);”
@Nicolas我照你说的做了,jquery函数仍然没有被调用,我不认为href是问题所在,因为它曾经工作过:/一定是其他东西,但我看不到它问题:你是在页面加载后添加你的
吗?在doc ready中,(在单击处理程序之前)添加:
警报($('.\notif')。长度)
-您得到的值是多少?关于
警报($(“[id=notif]”).length)的值是多少
<a href="#" id="notif" data-id="<?php echo $_SESSION['ID']; ?>" class="dropdown-toggle" data-toggle="dropdown">
                            <i class="icon-bell2"></i>
                            <span class="visible-xs-inline-block position-right">Activity</span>
                            <span class="status-mark border-orange-400"></span>
                        </a>