Javascript在PHP中不起作用。

时间:2014-12-24 07:31:04

标签: javascript php

我的剧本:

<?php
include 'theme.php';
/*ceklogin();*/
css();
if($_POST['wget-send'])
    {
        $formdir=$_POST['dir'];
        $formlink=$_POST['link'];
    $filelink = fopen('/root/wget/wget-download-link.txt',a);
    $filedir = fopen('/root/wget/wget-dir.txt',w);

    fwrite($filedir, $formdir);
    fwrite($filelink, $formlink."\n");
    /*
    exec('touch /root/wget/wget-download-link.txt',$out);
    exec('echo "'.$link.'" >> /root/wget/wget-download-link.txt',$out);
    exec('echo "'.$dir.'" > /root/wget/wget-dir.txt',$out);
        echo $out[2];
        exit();
    */
    }
echo "<form action=\"".$PHP_SELF."\" method=\"post\" id=\"WgetForm\">";
echo "Download directory:<br><input type=\"text\" name=\"dir\" size=\"15\" value=\"/mnt/usb/\"/><br>";
echo '<br><br>Download link:';
echo "<br><input type=\"text\" name=\"link\" size=\"62\" value=\"\"/><br><br>";
echo '<input type="submit" onclick="LinkAdded()" name="wget-send" value="Send" id="WgetID"/>';
echo "</form></div>";
echo '<script type="text/javascript">';

'function LinkAdded()'
    '{
            document.getElementById("WgetID").innerHTML = "Link added to wget";
    }'
'</script>'

foot();
echo '
</div>
</body>
</div>
</html>';
?>

我仍然不太了解如何在PHP中编写javascript,它给了我一个错误:

Parse error: syntax error, unexpected ''{' (T_CONSTANT_ENCAPSED_STRING) in /www/wget.php on line 33

但如果我把javascript放在<? ....?>的一边,那么页面运行良好,但javascript不会起作用。请帮忙。

5 个答案:

答案 0 :(得分:1)

试试这个

echo '<script type="text/javascript">

     function LinkAdded()
    {
            document.getElementById("WgetID").innerHTML = "Link added to wget";
    }
</script>'

答案 1 :(得分:0)

存在语法错误。请试试这个。

echo '<script type="text/javascript">';

echo 'function LinkAdded()
{
        document.getElementById("WgetID").innerHTML = "Link added to wget";
}
</script>';

答案 2 :(得分:0)

试试这个:

echo '<script type="text/javascript">'.

'function LinkAdded()'.
    '{
            document.getElementById("WgetID").innerHTML = "Link added to wget";
    }'.
'</script>';

echo '<script type="text/javascript">

function LinkAdded()
    {
            document.getElementById("WgetID").innerHTML = "Link added to wget";
    }
</script>';

答案 3 :(得分:0)

在每一行上回显,或删除引号以作为一个块回显:

echo '<script type="text/javascript">

    function LinkAdded()
    {
            document.getElementById("WgetID").innerHTML = "Link added to wget";
    }
</script>';

答案 4 :(得分:0)

我不会解析你的语法错误。自己使用代码linter来做到这一点。它们现在内置于免费的IDE中,您甚至可以将代码粘贴到在线语法检查器中

您没有为设置input的{​​{1}}设置innerHTML

更改

value

document.getElementById("WgetID").innerHTML = "Link added to wget"