开发者问题收集

$ 在 JQuery 中未定义[重复]

2015-07-03
4416

让我向大家展示一下,我将这段代码放在名为 consultas.php 的文件中

CONSULTAS.PHP

此文件显示包含数据的表格,位于名为 folio id="'.$row["folio"].'" 的列末尾,当我单击那里时,它会向我显示并转到 VISTAPREVIA.PHP 以获取有关此 folio 的更多数据,但在分页 #1 中它运行良好,现在当我要转到分页 #2 时,我再次单击它却不起作用,因为没有显示任何内容,错误告诉我: Uncaught ReferenceError: $ is not defined

<script type="text/javascript">     
        $(document).ready(function() {
            var table = $('#registros').DataTable({
                "paging": true                
            });
            //new $.fn.dataTable.AutoFill( table );
            $('.back').on("click", function(event)
            {            
                event.preventDefault();            
                location.reload();
            });

            $('.modificar').on("click", function(event)
            {            
                event.preventDefault();            
                //Cargamos el contenido del enlace
                var f = $(this).attr('id');
                $('#mainContainer').load(this.href, {folio: f}, function(){                     
                });
            });
            $('.vistaprevia').on("click", function(event)
            {            
                event.preventDefault();            
                //Cargamos el contenido del enlace
                var f = $(this).attr('id');
                $('#mainContainer').load(this.href, {folio: f}, function(){                     
                });
            });
            $('.detalle').on("click", function(event)
            {            
                event.preventDefault();
                var f = $(this).attr('id');
                $('<div></div>').load(this.href, {folio: f}).modal();                            
                
            });
        });
    </script>
<a href="#" class="back">REGRESAR ATRÁS</a>
<h1 class="titPer">CONSULTA DE LA TABLA</h1>
<div class="tabla">
    <table id="registros" class="display" cellspacing="0">
        <thead>
            <tr>
                <th>Folio</th>
                <th>Estatus</th>
                <th>Punto de Venta</th>
                <th>Usuario</th>
                <th>Acciones</th>            
            </tr>
        </thead>        
        <tbody>
            <?php
                while ($row = mysql_fetch_array($consulta)) {
            ?>
                <tr>                            
                    <td><?=$row['folio']?></td>                
                    <td><?=$row['estatus']?></td>                
                    <td><?=$row['punto_venta']?></td>
                    <td><?=$row['usuario']?></td>
                    <td>
                        <?php
                            if($_SESSION['permisos'] == 'VENDEDOR' || $_SESSION['permisos'] == 'JEFESUC' || $_SESSION['permisos'] == 'EMBARQUES'){
                                echo '
                                    <center>
                                        <a class="modificar icon-pencil" href="includes/vistaPrevia.php" id="'.$row["folio"].'"></a>
                                         | 
                                        <a class="detalle icon-eye-plus" href="includes/lightbox.php" id="'.$row["folio"].'"></a>
                                    </center>
                                ';                                
                            }else{
                                echo'
                                    <center>                                    
                                        <a class="vistaprevia icon-eye-plus" href="includes/vistaPrevia.php" id="'.$row["folio"].'"></a>
                                    </center>
                                ';
                            }
                        ?>                        
                    </td>
                </tr>
            <?php
                }
            ?>
        </tbody>
    </table>                 
</div>

VISTAPREVIA.PHP

<?php session_start(); ?>
<head>
<link href='http://fonts.googleapis.com/css?family=PT+Sans+Narrow' rel='stylesheet' type='text/css'>

</head>
<a href="includes/consultas.php" class="back">REGRESAR ATRÁS</a>
<h1 class="titPer">ACTUALIZACIÓN DE DATOS</h1>
<!-- <form action="includes/"></form> -->
<?php
    if($_SESSION['permisos'] == 'CALIDAD'){
        include('upRegCal.php');
    }
?>

<form action="includes/edit.php" enctype="multipart/form-data" id="formAct" method="POST" name="enviarForm">
    <?php
        if($_SESSION['permisos'] == 'VENDEDOR' || $_SESSION['permisos'] == 'JEFESUC' || $_SESSION['permisos'] == 'EMBARQUES'){
            include('upRegUser.php');
        }

        if($_SESSION['permisos'] == 'ADMINISTRADOR'){
            //include('upRegCal.php');
            echo "Hola Administrador";
        }
    ?>    
</form>

last

INDEX.PHP
我必须确保这部分,因为我放了正确的 Jquery 脚本,但我不知道为什么,我找不到问题,是的,我使用 Datables 脚本

<?php
    session_start();     
?>
<!DOCTYPE html>
<html>
    <head>  
        <meta http-equiv="Content-Type" content="text/html" charset="UTF-8"/>
        <title>Bienvenido</title>
        <script src="js/jquery-1.11.2.js"></script>     
        <script src="js/funciones.js"></script>
        <script src="libs/datatables/media/js/jquery.dataTables.js"></script>
        <script src="libs/datatables/extensions/AutoFill/js/dataTables.autoFill.js"></script>

        <script type='text/javascript' src='js/jquery.simplemodal.js'></script>
        <script type='text/javascript' src='js/basic.js'></script>

        <link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,300,400,600,700' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="css/normalize.css" type="text/css"/>    
        <link rel="stylesheet" href="css/estilos.css" type="text/css"/>     
        <link rel="stylesheet" href="css/estilosForm.css" type="text/css"/>
        <link type='text/css' href='css/basic.css' rel='stylesheet' media='screen' />       
   
        <link rel="stylesheet" href="libs/datatables/media/css/jquery.dataTables.css" type="text/css"/>
        <link rel="stylesheet" href="libs/datatables/extensions/AutoFill/css/dataTables.autoFill.css" type="text/css"/>     
        
    </head>
     
    <body>
        <div class="fondoHeader"></div>
        <header class="shadow">
            <nav>       
                <?php                               
                if(isset($_SESSION['usuario']))
                    include('includes/btnSiSession.php');                   
                else
                    include('includes/btnNoSession.php');                   
                ?>              
            </nav>          
        </header>       
        <div id='mainContainer'>        
            <?php                           
                include('includes/bienvenido.php');             
        
                if(isset($_SESSION['usuario'])){
                    echo "<script language='JavaScript'>"; 
                    // echo "document.getElementById('login').style.display='none'"; 
                    echo "document.getElementById('login').style.visibility='hidden'"; 
                    echo "</script>";
                }
                else{
                    echo "<script language='JavaScript'>"; 
                    // echo "document.getElementById('login').style.display='block'"; 
                    echo "document.getElementById('login').style.visibility='visible'"; 
                    echo "</script>";
                }
            ?>
        </div>
        <div class="clear"></div>
        <footer> 
            <?php
                include('includes/footer.php');
            ?>    
        </footer>
    </body>
</html>

更新 我把这个代码放到 jQuery CDN 脚本中

<script src="ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript">     
        $(document).ready(function() {
            var table = $('#registros').DataTable({
                "paging": true                
            });
            //new $.fn.dataTable.AutoFill( table );
            $('.back').on("click", function(event)
            {            
                event.preventDefault();            
                location.reload();
            });

            $('.modificar').on("click", function(event)
            {            
                event.preventDefault();            
                //Cargamos el contenido del enlace
                var f = $(this).attr('id');
                $('#mainContainer').load(this.href, {folio: f}, function(){                     
                });
            });
            $('.vistaprevia').on("click", function(event)
            {            
                event.preventDefault();            
                //Cargamos el contenido del enlace
                var f = $(this).attr('id');
                $('#mainContainer').load(this.href, {folio: f}, function(){                     
                });
            });
            $('.detalle').on("click", function(event)
            {            
                event.preventDefault();
                var f = $(this).attr('id');
                $('<div></div>').load(this.href, {folio: f}).modal();                            
                
            });
        });
    </script>
3个回答

consultas.php 中,您必须包括jQuery( &lt; script src =“ js/jquery-1.11.2.js”&gt;&lt;/script&gt; )在使用它之前,在您的 &lt; script&gt;

中,每个页面都不同,然后您必须在每个页面中添加jQuery。

示例

225711905
Léni
2015-07-03

在某些情况下,您必须使用 jQuery 而不是 $

第二个选项: jQuery(document).ready(function($) {{

此后,您可以将 $ 用作 jquery 的同义词。

radscheit
2015-07-03

此错误是因为您缺少 JQuery 库。如果您在页面底部(页脚)包含 Javascript 库(包括 JQuery),您可以

  • 在页面顶部包含 JQuery 库

或者

  • 将您的 Javascript 函数制作成一个通用 js 文件,并将其包含在页脚中,就在 Jquery 包含的下方。

这是 Jquery CDN 的 链接

ash__939
2015-07-03