<div id="pdf">
<script type="text/javascript">
function get_pdf_file( elem ) {
var filename = elem.options[elem.selectedIndex].value;
var file_id = elem.options[elem.selectedIndex].id;
var id = elem.options[elem.selectedIndex].index;
// output some stuff to console: it works
console.log( 'get_pdf_file( elem ) filename id: ' + id );
}
</script>
<div id="choose_pdf">
<form id="select_pdf_file">
<select name="pdf_file" onChange="get_pdf_file( this )">
<?php
for ( $i = 0; $i < $count_filenames; $i++ ) {
if ( $i == 0 ) {
echo '<option id="file_' . $i . '" value="' . $filenames[$i] . '" selected >' . $filenames[$i] . '</option>';
$pdf_file = $filenames[$i];
} else {
echo '<option id="file_' . $i . '" value="' . $filenames[$i] . '">' . $filenames[$i] . '</option>';
}
}
# output from above:
#<option id="file_1" value="tutorial_1.pdf" selected >tutorial_1.pdf</option>
#<option id="file_2" value="tutorial_2.pdf" >tutorial_2.pdf</option>
# ...
# ...
?>
</select>
</form>
</div>
<!-- here is the container to output the selected file "$pdf_file" (see above)-->
<object width="1000" height="803" type="application/pdf" data="<?php echo $pdf_file ?>?#zoom=58.7&scrollbar=1&toolbar=1&navpanes=1" id="pdf_content">
<p>Insert your error message here, if the PDF cannot be displayed.</p>
</object>
</div>
该变量$count_filenames
是数组中的元素数,该数组名为$filenames
包含各种 .pdf 文件的名称...
相信我错过了一些代码作为用户选择 tutorial_2.pdf 的操作,例如总是输出相同的文件,即 tutorial_1.pdf…</p>
请帮助解决这个问题!