从php引用外部javaScript

I have a function named

test() 

defined in a javaScript file called test.js which is reference from the following html:

<html>
<head>
    <script src="test.js"></script>
</head>
    <?php 
        echo "<script>test();</script>"; 
     ?>

<body>
</body>
</html>

I have verified that test.js works on it's own and the other javascript is being executed by the php. But I'm getting an undefined error.

Error: test() undefined

Can any one tell my how to properly reference a external javascript file from a php script?

put it in your body and test it again

Try like this

<html>
<head>
    <script src="test.js"></script>
</head>


<body>
    <?php 
        echo "<tag onClick='test()'>text text text </tag>"; 
     ?>
</body>
</html>

1- run the function manualy not with php : do some thing like :

<body onload ="alert('test');test();">

if worked test it:

<body onload ="alert('test');<?php echo "test();";?>">

if not worked your javascript function is not ok.

It should just work, have you really tried it like this? :

<html>
    <head>
        <script src="js/test.js"></script>
    </head>
    <body>
        <?php
            echo "<script>test();</script>"; 
        ?>
    </body>
</html>

You can try out this:

echo '<script type="text/javascript">','your_function();','</script>';