Javascript函数调用不起作用


javascript function call doesn't work

我有一些php, html和JS代码:

$files = getDirectoryList("/home/uploads/");
foreach($files as $file)
{
    ?>
    <input type="submit" onclick="writetofile("<?php echo $file; ?>")" value="Work " />     
    <?php 
    echo $file;
}

当我点击"工作"时,writetofile不会被调用,这是在HTML头部标签脚本的顶部定义的。为什么?

看起来您在JavaScript函数调用中错误地引用了字符串。将它们从双引号改为单引号。(这里假设$file作为字符串传递给函数,并且不应该在JavaScript中的某个地方定义为符号)。

<input type="submit" onclick="writetofile('<?php echo $file; ?>')" value="Work " />