onClick事件失败

时间:2014-06-13 15:03:59

标签: javascript xhtml

我的功能是:

<head>
<script type="text/javascript">
// Info popup window
function showInfo(infFilename) {
alert(infFilename);
popupWin = window.open('notes/"+infFilename+"','open_window','width=400,height=300,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=20,top=20' );
}
</script>
</head>

调用弹出窗口的php代码是:

<?php>
// check if metadata exists ( PicNotes is "filename.php" )
if ($row['PicNotes']) {
$icon = "<img src = \"images/info.png\"  onClick=\"showInfo($row[PicNotes])\" />";
}else{
$icon='';}

echo "<a href='images/".$row['vfile']."' rel='enlargeimage' rev='targetdiv:loadarea' title='&lt;b&gt;".$row['Title']."&lt;/b&gt;&lt;br /&gt;".$row['Medium']." &nbsp; &nbsp; &nbsp; ".$row['iw']." x ".$row['ih']." cm. $icon'><img border='1' src='images/".$row['tnfile']." ' alt=' '  width='".$row['tnx']."' height='".$row['tny']."' class='tn' /></a><br />";

?>

此行的html是(来自查看源):

<a href='images/0712120189y.jpg' rel='enlargeimage' rev='targetdiv:loadarea' title='&lt;b&gt;Broken Bridge in Water Meadow&lt;/b&gt;&lt;br /&gt;Gouache &amp; Pastel &nbsp; &nbsp; &nbsp; 24 x 19 cm. <img src = "images/info.png"  onClick="showInfo(wm_series.php)" />'><img border='1' src='images/0712120189z.jpg ' alt=' '  width='96' height='75' class='tn' /></a>

请有人看看我做错了什么。

1 个答案:

答案 0 :(得分:0)

这部分:

onClick=\"showInfo($row[PicNotes])\"

应该是:

onClick=\"showInfo('$row[PicNotes]')\"

你需要围绕filename参数引用,因为它是一个字符串。

此外,你有一个角色:

cm. $icon'>

应该是:

cm. $icon

你的弹出代码应该是:

function showInfo(infFilename) {
    alert(infFilename);
    popupWin = window.open('notes/'+infFilename,'open_window','width=400,height=300,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=20,top=20' );
}