如何获取输入字段的图像名称?

时间:2012-11-04 07:51:12

标签: php image

如下所示进行小型幻灯片演示。可以选择一个图像。如果选择一个图像,我想将相应的图像名称输入到输入字段。我怎样才能做到这一点?请帮忙。

 <div id="theImages">
            <a href="#" onclick="showPreview('images/image1_big.jpg','1');return false"><img src="images/image1.jpg" name="image1"></a>     
            <a href="#" onclick="showPreview('images/image2_big.jpg','2');return false"><img src="images/image2.jpg" name="image2"></a>     
            <a href="#" onclick="showPreview('images/image3_big.jpg','3');return false"><img src="images/image3.jpg" name="image3"></a>     
            <a href="#" onclick="showPreview('images/image4_big.jpg','4');return false"><img src="images/image4.jpg" name="image4"></a>     
            <a href="#" onclick="showPreview('images/image5_big.jpg','5');return false"><img src="images/image5.jpg" name="image5"></a>     
            <a href="#" onclick="showPreview('images/image6_big.jpg','6');return false"><img src="images/image6.jpg" name="image6"></a>     
            <a href="#" onclick="showPreview('images/image7_big.jpg','7');return false"><img src="images/image7.jpg" name="image7"></a>     
            <a href="#" onclick="showPreview('images/image8_big.jpg','8');return false"><img src="images/image8.jpg" name="image8"></a>
 </div>

1 个答案:

答案 0 :(得分:0)

试试这个:(不完美,但它能完成这项工作)

 <div id="theImages">
    <a href="#" onclick="showPreview('images/image1_big.jpg','1');return false" name="image1"><img src="images/image1.jpg"></a>     
    <a href="#" onclick="showPreview('images/image2_big.jpg','2');return false" name="image2"><img src="images/image2.jpg"></a>     
    <a href="#" onclick="showPreview('images/image3_big.jpg','3');return false" name="image3"><img src="images/image3.jpg"></a>     
    <a href="#" onclick="showPreview('images/image4_big.jpg','4');return false" name="image4"><img src="images/image4.jpg"></a>     
    <a href="#" onclick="showPreview('images/image5_big.jpg','5');return false" name="image5"><img src="images/image5.jpg"></a>     
    <a href="#" onclick="showPreview('images/image6_big.jpg','6');return false" name="image6"><img src="images/image6.jpg"></a>     
    <a href="#" onclick="showPreview('images/image7_big.jpg','7');return false" name="image7"><img src="images/image7.jpg"></a>     
    <a href="#" onclick="showPreview('images/image8_big.jpg','8');return false" name="image8"><img src="images/image8.jpg"></a>

    <br /><br />

    <form action="" method="">
        <input type="text" name="drop" id="drop" />
    </form>
 </div>

 <script>
    function showPreview(fileName,fileNumber){
        //document.getElementById("drop").value = fileName; // full filename + path
        var filename_no_path = fileName.split('/');
        document.getElementById("drop").value = filename_no_path[1] // just filename - no path
    }
 </script>