Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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根本不工作,但运行其他Javascript代码_Javascript_Php_Jquery - Fatal编程技术网

Jquery根本不工作,但运行其他Javascript代码

Jquery根本不工作,但运行其他Javascript代码,javascript,php,jquery,Javascript,Php,Jquery,我的jquery遇到了一个问题。我有一个有多条记录的表,每条记录都有删除链接。单击该链接时,特定记录将被删除。这很好,但我正在尝试的是,当一条记录被删除时,它会在没有任何页面刷新的情况下消失。为此,我有一个jquery代码,它在独立页面上运行良好,但当我试图将其与实际代码集成时,什么也没有发生。我用jQuery替换了$,但仍然没有发生任何事情。我还检查了其他原因,但没有任何效果。有人能指出我可能遗漏了什么或者我做错了什么吗。代码如下: 这是我的行代码,它位于foreach中,因此可以创建多个行代

我的jquery遇到了一个问题。我有一个有多条记录的表,每条记录都有删除链接。单击该链接时,特定记录将被删除。这很好,但我正在尝试的是,当一条记录被删除时,它会在没有任何页面刷新的情况下消失。为此,我有一个jquery代码,它在独立页面上运行良好,但当我试图将其与实际代码集成时,什么也没有发生。我用jQuery替换了$,但仍然没有发生任何事情。我还检查了其他原因,但没有任何效果。有人能指出我可能遗漏了什么或者我做错了什么吗。代码如下:

这是我的行代码,它位于foreach中,因此可以创建多个行代码

<tr class="showdel">
   <td class="align"><input type="checkbox" name="instanceids[]" id="checkid" value="<?php echo $instanceid; ?>" /></td>
   <td class="align"><?php echo $i++.'.'; ?></td>
   <td><?php echo $title; ?></td>
   <td><a href="javascript:void(0);" class="delete" id="<?php echo $instanceid; ?>">Delete</a></td>
</tr>

下面是我的jquery代码,它删除了记录,然后它就消失了。它在这一页的开头部分

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
        jQuery(function()
        {
            jQuery(".delete").click(function()
            {
                var element = jQuery(this);
                var del_id = element.attr("id");
                var info = 'id=' + del_id;
                if(confirm("Are you sure you want to delete this?"))
                {
                    jQuery.ajax({
                        type: "POST",
                        url: "content_list.php",
                        data: info,
                        success: function() {}
                    });

                    jQuery(this).parents(".showdel").animate({ backgroundColor: "#003" }, "slow")
                    .animate({ opacity: "hide" }, "slow");
                }
                return false;
            });
        });
        </script>

jQuery(函数()
{
jQuery(“.delete”)。单击(函数()
{
var元素=jQuery(this);
var del_id=element.attr(“id”);
var info='id='+del_id;
如果(确认(“是否确实要删除此?”))
{
jQuery.ajax({
类型:“POST”,
url:“content_list.php”,
数据:信息,
成功:函数(){}
});
jQuery(this).parents(“.showdel”).animate({backgroundColor:“#003”},“slow”)
.animate({opacity:“hide”},“slow”);
}
返回false;
});
});
请指出我做错了什么。提前谢谢

附:这是我的整个头部。看看这是否有帮助。可能是脚本的顺序错误

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title><?php echo $client; ?> Admin</title>
    <!-- bootstrap core css -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- custom css -->
    <link href="css/sb-admin.css" rel="stylesheet">

    <!-- style.css -->
    <link href="css/style.css" rel="stylesheet">

    <!-- paginng css -->
    <link href="css/pagination.css" rel="stylesheet">

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script type="text/javascript">
    jQuery(".delete").click(function()
    {
        var element = jQuery(this);
        var del_id = element.attr("id");
        var info = 'id=' + del_id;
        if(confirm("Are you sure you want to delete this?"))
        {
            jQuery.ajax({
                type: "POST",
                url: "content_list.php",
                data: info,
                success: function() {}
            });

            jQuery(this).parents(".show").animate({ backgroundColor: "#003" }, "slow")
            .animate({ opacity: "hide" }, "slow");
        }
        return false;
    });
    </script>

    <!-- form validation scripts -->
    <script type="text/javascript" src="js/validate_category.js"></script>
    <script type="text/javascript" src="js/validate_subcategory.js"></script>
    <script type="text/javascript" src="js/validate_subsubcategory.js"></script>
    <script type="text/javascript" src="js/selectall.js"></script>

    <script type="text/javascript" src="js/validate_content.js"></script>
    <script type="text/javascript" src="js/validate_resource.js"></script>
    <script type="text/javascript" src="js/validate_data.js"></script>
    <script type="text/javascript" src="js/ajax_scripts.js"></script>
</head>

管理
jQuery(“.delete”)。单击(函数()
{
var元素=jQuery(this);
var del_id=element.attr(“id”);
var info='id='+del_id;
如果(确认(“是否确实要删除此?”))
{
jQuery.ajax({
类型:“POST”,
url:“content_list.php”,
数据:信息,
成功:函数(){}
});
jQuery(this).parents(“.show”).animate({backgroundColor:”#003“},“slow”)
.animate({opacity:“hide”},“slow”);
}
返回false;
});
正如下面Alpesh Panchal指出的,我的表也是通过ajax调用加载的

  • 确保在页面加载期间使用firebug控制台检查任何javascript错误。有时javascript错误会阻止其他javascript的执行

  • 确保您的表没有被ajax调用加载。如果是,那么jQuery的click事件将不会绑定到它。要绑定它,需要使用ajaxStop()事件处理程序绑定delete函数

  • 如果ajaxStop()不起作用,那么您可以单独创建delete click函数,并在链接的“onclick”事件中调用它

  • e、 g


    由于数据表是通过ajax调用加载的,因此在加载数据之前试图设置事件处理程序时,
    jQuery(“.delete”)
    的选择实际上是空的。因此,解决方案是将事件处理程序设置为
    文档本身,并为
    .delete
    元素设置一个过滤器。像这样:

    jQuery(document).on('click',".delete",(function()
    {
      //Your code
    });
    

    使用jQuery
    .animate()
    方法,只能对数值设置动画(如“边距:30px”)。字符串值不能设置动画(如“背景色:红色”)


    使用jQuery的
    .css()
    方法更改颜色和/或隐藏元素,而不是
    animate

    console中有错误吗?调试代码:在不同级别调用一些console.log,查看脚本是否执行,最外层的函数是否执行,等等。返回结果。是否尝试
    jQuery(.delete”)。打开('click',function(){
    而不是
    click
    @Muhammad Atif:-没有错误,没有警告。它根本没有响应。我尝试添加一个警报框,但仍然没有响应。尝试删除jQuery(function(),只提供click函数)
    jQuery(document).on('click',".delete",(function()
    {
      //Your code
    });