I dont对php说新话,对如何在php和javascript之间做事有好的想法。
<!doctype html>
<html>
<head>
<Script type="text/javascript">
function show(m)
{
var k = document.getElementById(m);
k.src="four.jpg";
}
</head>
<body>
<? --some php code--
$i = 2;
$row[$i] = "somefilename";
printf( <img src="%s" id="%d" onclick="show($i)"/> , $row[$i],$i);
?>
This is my sample.php file.I wanted to raise a onclick event for the image tag through javascript,The img tag is created using php script and I want it to be like these
onclick="show($i)" should be made like below
onclick="show( 2 )" <!-- and here 2 is the value of php variable
I had tried these way
onclick="show( $i )" but it passes $i as the parameter to javascript show() function
but not the value 2
请帮助我这样做。 实际是可能的? 正如我知道javascript是个浏览器,而php是服务器的附带说明,我们是否能够将变数从php移至用这些方式?