我的html:
<form action="submitPage.php" method="post" onsubmit="savePathInVar();">
<table>
<tr>
<td><img src="<?php echo $path; ?>" onclick="changecolor(this);" /></td>
<td><img src="<?php echo $path; ?>" onclick="changecolor(this);" /></td>
</tr>
<input type="hidden" value="ClickedImaged" />
<input type="submit" value="Submit" />
</table>
</form>
ps:$path = "inventory_images/$id.jpg";
我的函数changecolor():
function changecolor(img)
{
var images = document.getElementsByTagName("img");
for(var i=0,j=images.length; i<j; i++)
{
images[i].style.borderColor="#000";
}
img.style.borderColor="#F00";
//Operate on img location as before
savePathInVar(img.src);
}
我的函数 savePathInVar():
function savePathInVar(ImgLocation)
{
//How do i save the path of the clicked image in a variable now?
}
我现在如何将单击图像的路径保存在变量中?以及如何将此变量放入表格下方的输入隐藏字段中?谁能帮助我?
如果有人可以帮助我,那就太好了.. 我对 javascript 很陌生 :) 问候!