<?php
echo "
<script language=javascript>
function test(){
alert('hello');
}
</script>";
?>
<input type=button value=click onclick='test()'>
echo "
<script language=javascript>
function test(){
alert('hello');
}
</script>";
?>
<input type=button value=click onclick='test()'>
onclick后面只能是客服端运行(js),而你的fucntion是php的函数,是在服务器端运行的