2014-06-13 46 views
-1

My功能是:onClick事件失敗

<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> 

請有人看到我做錯了什麼。

+0

'showInfo( 'wm_series.php' )'需要引用這個名字。 –

+0

看一看' Barmar

回答

0

這一部分:

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

應該是:

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

你需要引號將文件名參數,因爲它是一個字符串。

而且,你這裏有一個特點:

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'); 
} 
+0

Thenks Barmar but I have already tried that but is stops php processing the line properly. The output becomes:
''> ' – Sabreur

+0

的HTML這個輸出對我來說是正確的。 – Barmar

+0

雙引號並轉義它們會產生相同的結果。 – Sabreur