-1

我正在尝试通过 php 从我的服务器获取图像,并且我希望具有 onClick 功能,但它不起作用以下是我的代码示例:

<?php
$conn = ftp_connect("myserver") or die("Could not connect");
ftp_login($conn,"username","password");

$images = ftp_nlist($conn,"folder");
$r = count($images);



for($i=0;$i<$r;$i++)
{   
 //echo "  $images[$i]  ";
echo"<img id= '$i' class = '' border='1'   src='mysource' width='300' height='250'>"; 
echo "<button onClick= 'hide()'> Print </button>";
echo "<button> Email </button>";    
echo "<button> Text Me </button>";
echo "</br>";
}

ftp_close($conn);
?>

以下是我的javascript代码

function hide()
  {
    var t = document.getElementById(x); 
    t.setAttribute(class, print);   
     }

当我单击打印按钮时,它甚至都没有调用该函数,因为这一切都在 .php 文件中。感谢您的帮助。

4

1 回答 1

0

试试这个:

echo "<script type='text/javascript'>function hide_it(){alert('Entering Function hide_it()?'); /*var t = document.getElementById(x); t.setAttribute(class, print);*/}</script>";

for($i=0;$i<$r;$i++)
{   
     //echo "  $images[$i]  ";
     echo"<img id= '$i' class = '' border='1'   src='mysource' width='300' height='250'>"; 
     echo "<button type='button' onclick='javascript:hide_it()'> Print </button>";
     echo "<button> Email </button>";    
     echo "<button> Text Me </button>";
     echo "</br>";
}
于 2013-06-01T18:15:04.437 回答