javascript(jQuery)-单个脚本无法在我的2个单独页面中工作

javascript(jQuery)-单个脚本无法在我的2个单独页面中工作,javascript,php,jquery,Javascript,Php,Jquery,我有两个单独的页面:issuement\u filter.php和memo\u list.php和一个脚本。我的问题是,我不能让它在发行过滤器.php上工作,但在备忘录列表.php中工作得非常完美。但有时情况正好相反 这是我的密码: 发布\u filter.php <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.3.js"></script> <script ty

我有两个单独的页面:
issuement\u filter.php
memo\u list.php
和一个脚本。我的问题是,我不能让它在
发行过滤器.php上工作,但在
备忘录列表.php
中工作得非常完美。但有时情况正好相反

这是我的密码:

发布\u filter.php

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.3.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
<script type="text/javascript" class="init">

$(document).ready(function() {
    $('#example').DataTable( {
        "order": [[ 0, "desc" ]]
    } );
} );

</script>

<h2>Issuances</h2>

<table id="example" class="table table-striped table-bordered">
    <thead>
        <tr>
            <th width="8%">ID</th>
            <th width="18%">Issuance Type</th>
            <th width="18%">Category</th>
            <th width="18%">In Charge</th>
            <th width="18%">Date Released</th>
            <th align="18%">Issuance Title</th>
        </tr>
    </thead>
    <tbody>

        <?php

            include "../dbconnect/dbconnection2015.php";
            mysql_query("SET NAMES utf8");          
            /////////////////////////////////

            /*Values from the other page*/
                $type = htmlentities($_POST['type']);
                $year = htmlentities($_POST['year']);
                $in_charge = htmlentities($_POST['in_charge']);
                $category = htmlentities($_POST['category']);
                mysql_query("SET NAMES utf8");

                if (empty($type) AND !empty($year) AND !empty($category) AND !empty($in_charge)) { 
                    $filter = "WHERE Year = '$year' AND Category = '$category' AND In_Charge = '$in_charge'";
                }
                elseif(empty($year) AND !empty($type) AND !empty($in_charge) AND !empty($category)){
                    $filter = "WHERE Issuance_Type = '$type' AND Category = '$category' AND In_Charge = '$in_charge'";
                }
                elseif(empty($in_charge) AND !empty($year)  AND !empty($type)  AND !empty($category)){
                    $filter = "WHERE Year = '$year' AND Category = '$category' AND Issuance_Type = '$type'";
                }
                elseif(empty($category) AND !empty($year) AND !empty($type) AND !empty($in_charge)){
                    $filter = "WHERE Year = '$year' AND Issuance_Type = '$type' AND In_Charge = '$in_charge'";
                }
                elseif(empty($type) AND empty($year) AND !empty($in_charge)  AND !empty($category)){
                    $filter = "WHERE Category = '$category' AND In_Charge = '$in_charge'";
                }
                elseif(empty($in_charge) AND empty($category) AND !empty($year) AND !empty($type)){
                    $filter = "WHERE Year = '$year' AND Issuance_Type = '$type'";
                }
                elseif(empty($type) AND empty($in_charge) AND !empty($year) AND !empty($category)){
                    $filter = "WHERE Category = '$category' AND Year = '$year'";
                }
                elseif(empty($category) AND empty($year) AND !empty($in_charge) AND !empty($type)){
                    $filter = "In_Charge = '$in_charge' AND Issuance_Type = '$type'";
                }
                elseif(empty($type) AND empty($category) AND !empty($in_charge) AND !empty($year)){
                    $filter = "WHERE In_Charge = '$in_charge' AND Year = '$year' ";
                }
                elseif(empty($in_charge) AND empty($year) AND !empty($type) AND !empty($category)){
                    $filter = "WHERE Category = '$category' AND Issuance_Type = '$type'";
                }
                elseif(!empty($type) AND empty($year) AND empty($category) AND empty($in_charge)){
                    $filter = "WHERE Issuance_Type = '$type'";
                }
                elseif(!empty($year) AND empty($type) AND empty($category) AND empty($in_charge)){
                    $filter = "WHERE Year = '$year'";
                }
                elseif(!empty($category) AND empty($year) AND empty($type) AND empty($in_charge)){
                    $filter = "WHERE Category = '$category'";
                }
                elseif(!empty($in_charge) AND empty($year) AND empty($category) AND empty($year)){
                    $filter = "WHERE In_Charge = '$in_charge'";
                }
                elseif(!empty($type) AND !empty($in_charge) AND !empty($year) AND !empty($category)) {
                    $filter = "WHERE Issuance_Type = '$type' AND In_Charge = '$in_charge' AND Year = '$year' AND Category = '$category'";
                }
                else{
                    $filter = "";
                }
                // echo $filter;

                $sql = "SELECT * FROM issuances $filter ORDER BY Issuance_ID DESC";
                $fetch_num_memo = mysql_query($sql);
                if ($fetch_num_memo && mysql_num_rows($fetch_num_memo) > 0){
                        while($row = mysql_fetch_assoc($fetch_num_memo)){
                        $string = $row['Issuance_Heading'];                     
                        echo "<tr>";
                        echo "<td>".$row['Issuance_ID']."</td>";    
                        echo "<td>".$row['Issuance_Type']."</td>";
                        echo "<td>".$row['Category']."</td>";
                        echo "<td>".$row['In_Charge']."</td>";
                        echo "<td>".$row['Date_Released']."</td>";
                        echo "<td><a class='filename' href='{$row['URL']}' target='_blank'>{$row['Issuance_Title']}</a></td></tr>";
                    }
                }
                else {
                    # Do Nothing
                }
        ?>
    </tbody>                        
</table>

$(文档).ready(函数(){
$('#示例')。数据表({
“订单”:[[0,“描述”]]
} );
} );
发行
身份证件
发行类型
类别
主管
发布日期
发行名称
memo_list.php

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.3.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
<script type="text/javascript" class="init">

$(document).ready(function() {
    $('#example').DataTable( {
        "order": [[ 0, "desc" ]]
    } );
} );

</script>

<h2>Issuances</h2>

<table id="example" class="table table-striped table-bordered">
    <thead>
        <tr>
            <th width="5%">ID</th>
            <th width="15%">Issuance Type</th>
            <th width="15%">Date Released</th>
            <th align="15%">Issuance Title</th>
        </tr>
    </thead>
    <tbody>

        <?php

            include "dbconnect/dbconnection2015.php";
            mysql_query("SET NAMES utf8");
            $fetch_num_memo = mysql_query("SELECT * FROM issuances WHERE $filter ORDER BY Issuance_ID DESC");
            if ($fetch_num_memo && mysql_num_rows($fetch_num_memo) > 0){
                while($row = mysql_fetch_assoc($fetch_num_memo)){
                $string = $row['Issuance_Heading'];                     
                echo "<tr>";
                echo "<td>{$row['Issuance_ID']}</td>";  
                echo "<td> {$row['Issuance_Type']}</td>";
                echo "<td>".$row['Month'].". ".$row['Date'].", ".$row['Year']."</td>";
                echo "<td><a class='filename' href='{$row['URL']}' target='_blank'>{$row['Issuance_Title']}</a></td></tr>";
                }
            }
            else {
            echo '<script type="text/javascript">
            window.location = "sdo_issuances.php"
            </script>';
            }
        ?>

    <tbody>                        
</table>

$(文档).ready(函数(){
$('#示例')。数据表({
“订单”:[[0,“描述”]]
} );
} );
发行
身份证件
发行类型
发布日期
发行名称
还有剧本:

<script type='text/javascript'>
$(document).ready(function(){
    $('.filename').click(function(){
        var filename = ($(this).text());
         $.post('sdo_insert.php', {postname:filename}, function (data) {
                // $('.insert').html(data);
         });
         alert('You clicked : ' + filename);
       });
    });
</script>

$(文档).ready(函数(){
$('.filename')。单击(函数(){
var filename=($(this.text());
$.post('sdo_insert.php',{postname:filename},函数(数据){
//$('.insert').html(数据);
});
警报(“您单击:”+文件名);
});
});
我无法使脚本在两个页面中都工作,也无法找出问题所在。请帮我解决这个问题。谢谢你试试这个

  <script type='text/javascript'>
    $(function() {
    $('.filename').click(function(){
     var filename = ($(this).text());
     $.post('sdo_insert.php', {postname:filename}, function (data) {
            // $('.insert').html(data);
     });
     alert('You clicked : ' + filename);
   });
  });
</script>

$(函数(){
$('.filename')。单击(函数(){
var filename=($(this.text());
$.post('sdo_insert.php',{postname:filename},函数(数据){
//$('.insert').html(数据);
});
警报(“您单击:”+文件名);
});
});
试试这个

  <script type='text/javascript'>
    $(function() {
    $('.filename').click(function(){
     var filename = ($(this).text());
     $.post('sdo_insert.php', {postname:filename}, function (data) {
            // $('.insert').html(data);
     });
     alert('You clicked : ' + filename);
   });
  });
</script>

$(函数(){
$('.filename')。单击(函数(){
var filename=($(this.text());
$.post('sdo_insert.php',{postname:filename},函数(数据){
//$('.insert').html(数据);
});
警报(“您单击:”+文件名);
});
});

是否尝试使用开发者工具栏检查脚本是否已加载?最后的剧本写在哪里?它是内联文件还是外部文件?如果是外部文件,在这两个页面中是如何引用的?我在页面末尾编写了脚本。这是一个内部脚本,所以我在两页中都写了它。另外,我在firefox中试用了开发人员工具,脚本已经加载。您是否尝试使用开发人员工具栏检查脚本是否已加载?最后的剧本写在哪里?它是内联文件还是外部文件?如果是外部文件,在这两个页面中是如何引用的?我在页面末尾编写了脚本。这是一个内部脚本,所以我在两页中都写了它。而且,我在firefox中尝试了开发工具,脚本也被加载了。