2

我有 3 个 PHP 页面,它们的功能是显示存储在数据库中的图像,如果您双击一个图像,则该图像的属性会显示在屏幕上。

  • 更新.php
  • 列表.php
  • update_list.php

“update.php”有 2 个选择框:主类别和子类别。如果提交, list.php”通过jquery load()显示在“update.php”中。它也与“list.php”和*“update_list.php”*具有相同的关系。“list.php”包含图像,如果您双击一张图像,*“update_list.php”* 将显示在屏幕左侧。

这些是代码:

更新.php

 <?php
include('../../include/settings.php');
?>

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="../../mystyle.css" />
<script src="../../include/all.js"></script>
<script type="text/javascript">
$(document).ready(function(){

    $("#buttonList").click(function(){
        var main_id=$('#selectMainProList').val();
        var sub_id=$('#selectSubProList').val();
        $('#list').load('list.php?sub_id='+sub_id+'&main_id='+main_id);
        });

    $("#selectMainProList").change(function(){
        var main_cat_id=$('#selectMainProList').val();
        $('#selectSubProList').load('update.html', function(){
            $('#spanSubProList').load('update.php?selected='+main_cat_id+' #selectSubProList');
        });
    });


});
</script>
</head>
<body>
<?php
    $posted_parent = getGet('selected'); //birbirine bağlı selectboxlar'da main selectbox'ın id'sini tutar.
?>
<form id="formProList" method="POST">
    <table align="center">
        <tr>
            <td>Ana Kategoriyi Seçiniz</td>
            <td>
                <span id="spanMainProList" name="spanMainProList">
                    <select id="selectMainProList" name="selectMainProList">
                        <option value="0">--------------------------</option>
                        <?
                            $sql="Select * from kategori where ust_kat_id='0'";
                            $result=mysql_query($sql);
                            while($row = mysql_fetch_row($result))
                            {
                                $main_pro_id=$row[0];
                                $main_pro_name=$row[1]; 

                                echo "<option value='".$main_pro_id."'>".$main_pro_name."</option>";

                            }
                        ?>
                    </select>
                </span>
            </td>
        </tr>
        <tr>
            <td>Alt Kategoriyi Seçiniz</td>
            <td>
                <span id="spanSubProList">
                    <select id="selectSubProList" name="selectSubProList">
                        <option value="0">--------------------------</option>
                        <?
                            $sql="Select * from kategori where ust_kat_id='$posted_parent'";
                            $result=mysql_query($sql);
                            while($row = mysql_fetch_row($result))
                            {
                                $sub_pro_id=$row[0];
                                $sub_pro_name=$row[1];  

                                echo "<option value='".$sub_pro_id."'>".$sub_pro_name."</option>";
                            }
                        ?>
                    </select>
                </span>
            </td>
        </tr>
        <tr>
            <td></td>
            <td><input type="button" id="buttonList" name="buttonList" value="Search"/></td>    
        </tr>   
    </table>
</form>
<div id="list"></div>
</body>
</html>

列表.php

<?php
include('../../include/settings.php');
?>

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="../../css/mystyle.css" />
<link rel="stylesheet" type="text/css" href="../../css/tooltip.css" />
<script src="../../include/all.js"></script>
<script type="text/javascript">
$(document).ready(function(){

    $("img").dblclick(function(){
        var id=$('#hiddenID').val();
        alert(id);
        $("#update_pro").slideToggle();
        $('#update_pro').load('update_list.php?id='+id);
        });





});
</script>
</head>
<body>
<?php
    $main_cat_id=getGet("main_id"); 
    $sub_cat_id=getGet("sub_id");   
?>
<form>
<table align="center">
<tr>
<td>    
    <table align="center">
        <tr>
            <?php
                $sql="SELECT * FROM urun WHERE alt_kat_id='$sub_cat_id' and ana_kat_id='$main_cat_id'";
                $result=mysql_query($sql);
                $count=mysql_num_rows($result);
                $i=0;
                while($row=mysql_fetch_assoc($result,0))
                {
                    $image_dir=$row["resim"];
                    $id=$row["id"];
                    $isim_tr=$row["isim_tr"];
                    $aciklama_tr=$row["aciklama_tr"];
                    if($i!=2)
                    {
                        echo "<td>";
                        echo "<a href='#' class='tt'><img src='$image_dir' height='150' width='150'/><span class='tooltip'><span class='top'></span><span class='middle'>$aciklama_tr--$id</span><span class='bottom'></span></span></a><br>";
                        echo "<center><input type='button' id='buttonProDelete' value='Delete' /></center>";
                        echo "<br><center>$isim_tr</center>";
                        echo "<input type='hidden' id='hiddenID' value='$id' />";
                        echo "</td>";
                        $i++;
                    }
                    else
                    {
                        echo "<tr>";
                        echo "</tr>";
                        echo "<td>";
                        echo "<a href='#' class='tt'><img src='$image_dir' height='150' width='150'/><span class='tooltip'><span class='top'></span><span class='middle'>$aciklama_tr--$id</span><span class='bottom'></span></span></a><br>";
                        echo "<center><input type='button' id='buttonProDelete' value='Delete' /></center>";
                        echo "<br><center>$isim_tr</center>";
                        echo "<input type='hidden' id='hiddenID' value='$id' />";
                        echo "</td>";
                        $i=1;

                    }
                }
            ?>
        </tr>
    </table>
</td>
<td><div id="update_pro"></div></td>
</tr>
</table>
</form>
</body>
</html>

更新列表.php

<?php
include('../../include/settings.php');
?>

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="../../css/mystyle.css" />
<script src="../../include/all.js"></script>
<script type="text/javascript">

</script>
</head>
<body>
<?php 

    $id=getGet("id");
    echo $id;

?>


</body>
</html>

问题是我无法获取我双击的图像的真实 id。我总是获取第一个的 id!我想单击图像,然后,我想在同一页面中显示该图像的属性。我该怎么做?

4

1 回答 1

1

使用$(this)<--get jquery 对象 jquery 功能

this<-- 获取 DOM 元素 - javascript 功能

$("img").dblclick(function(){
    var id=$(this).val();  // <-- $(this) for current clicked image
    alert(id);
    $("#update_pro").slideToggle();
    $('#update_pro').load('update_list.php?id='+id);
});

你还说你想要 id 所以而不是像下面那样val()得到id

$(this).attr('id');

或者

this.id
于 2012-08-01T14:25:50.157 回答