例如这样一个例子(不对的)
<?php
function aa($a)
{
  echo "<javascript>alert('dfs')</javascript>";
}echo "<html><body>";
$a="234234";
echo "<input name=checkbox type=checkbox onclick='aa($a)' value=checkbox>";
echo "</body></html>";
?>

解决方案 »

  1.   

    直接调用不行,只有用PHP输出js代码,才能调用js代码中的函数.所以最终还是调用js..
      

  2.   

    在提交的时候调用看看我的一个进行检查的就知道了:
    <? include_once("public_user.php");
    include_once("public_func.php");
    include_once("PageDisplay.php");
    $db = new PageDisplay();?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <link rel="stylesheet" href="/admin/css/css.css">
    <title>增加</title>
    <SCRIPT language=JavaScript src="js/datesel/date.js"></SCRIPT>
    <SCRIPT language=JavaScript src="js/datesel/JSDateFunction.js"></SCRIPT>
    <script language="JavaScript">
    function checkchar(el)
    {
       //如果含有非字母数字 返回 true
       var text1="abcdefghijklmnopqrstuvwxyz1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZ,()!@$%&#*~.;_-=+-{}[]?'";
       for(i=0;i<=el.length-1;i++)
       {
          char1=el.charAt(i);
          index=text1.indexOf(char1);
          if(index==-1){
           return true;//非法
          }  
         //没有
       }
       return false;
    }function checknumeric(el)
    {
       //如果含有非字母数字 返回 true
       var text1="1234567890";
       for(i=0;i<=el.length-1;i++)
       {
          char1=el.charAt(i);
          index=text1.indexOf(char1);
          if(index==-1){
           return true;//非法
          }  
         //没有
       }
       return false;
    }
    function Check(){ for( var i=0;i<document.form1.elements.length;i++){
    if(document.form1.elements[i].type == 'text'){
    if( '' == document.form1.elements[i].value ){
    alert("请输入值!");
    document.form1.elements[i].focus();
    return false;
    }
    }
    }

    var kv=document.form1.keywords.value;
    if((kv.length)>300)
    {
    alert("the keywords.length is too long (<300)");
    return false;
    }

    var av=document.form1.author.value;
    if((av.length)>100)
    {
    alert("the author.length is too long (<100)");
    return false;
    }
    var pv=document.form1.pagetitle.value;
    if((pv.length)>100)
    {
    alert("the pagetitle.length is too long (<100)");
    return false;
    }
    if('' != document.form1.teimimage.value) {
    a = document.form1.teimimage.value;
    a = a.toLowerCase();
    var noimg = /.+\.gif|\.jpg/;
    if(null == a.match(noimg) )
    {
    alert('please select a image file!');
    return false;
    }
    }
    return (true);
    }
    </script></head><body bgcolor="#E8E8E8" ><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <form name=form1 ENCTYPE="multipart/form-data" method='post' action="add_finish.html" onSubmit="return Check()" >
    <IFRAME id=CalFrame style="DISPLAY: none; Z-INDEX: 100; WIDTH: 148px; POSITION: absolute; HEIGHT: 194px; left: 581px; top: 66px" marginWidth=0 marginHeight=0 src="js/datesel/calendar.htm" frameBorder=0 noResize scrolling=no>
        </IFRAME>
      <tr bgcolor="#336699">
        <td  width="30" class="text">&nbsp;</td>
        <td  class="PTitle" height=30>
        Pages Add</td>
        <td  width="30" class="text">&nbsp;</td>
      </tr>
      <TR><TD colspan=2 align='center'>
    <?
    echo "<font class=TTitle><a href='list.html?pageid=".$pageid."&unitid=".$unitid."'> back to list</a></font>";
    echo "<br><br>";
    ?>
    <input type=reset name=reset value='CANCEL'>&nbsp;&nbsp;&nbsp;&nbsp;
    <input type=submit name=submit value='ADD' ></td></tr>
    </table><tr><td>
    <table align="center" width="90%" border="1" cellspacing="0" cellpadding="5" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF" class="text">
    <form name=form1 ENCTYPE="multipart/form-data" method='post' action="add_finish.html" onSubmit="return Check()" >
    <IFRAME id=CalFrame style="DISPLAY: none; Z-INDEX: 100; WIDTH: 148px; POSITION: absolute; HEIGHT: 194px; left: 581px; top: 66px" marginWidth=0 marginHeight=0 src="js/datesel/calendar.htm" frameBorder=0 noResize scrolling=no>
        </IFRAME>
    <TR><TD colspan=2 align='center'>&nbsp;</td></tr><?
    $db->PageAdd("");
    ?>
    <TR><TD colspan=2 align='center'>
    <input type=hidden name=unitid value=<?=$unitid?> >
    <input type=reset name=reset value='CANCEL'>&nbsp;&nbsp;&nbsp;&nbsp;
    <input type=submit name=submit value='ADD' >
    </td></tr>
    </form>
    <table width="100%" border="0" cellspacing="0" cellpadding="2">
      <tr bgcolor="#4b74a9">
        <td width="30" class="text">&nbsp;</td>
        <td width="8" class="text" align="right">
        </td>
        <td width="270" class="text" align="left"></td>
        <td class="bottom"  align="center"></td>
        <td width="150"class="bottom"  align="center">
        </td>
        <td width="150" class="text" align="left">
        </td>
       <td width="30" class="text">&nbsp;</td>
      </tr>
    </table>
    <center><font class="text">2002-2004 &copy; in2english.com.cn All Rights Reserved.</font></center>
    </td></tr>
    </table>
    </body>
    </html>
      

  3.   

    onclick触发php的函数,肯定需要递交一次,不管是post,还是get
    因为php是在服务器端运行的,也就是说在你看到页面的时候,php已经全部运行完了,要返回值给php页面,必须递交.
      

  4.   

    <?php
    function aa()
    {
      echo "<script>";
      echo "function a(a)";
      echo "{alert(a)}";
      echo "</script>";
    }
    $a="234234";
    aa();
    echo "<input name=checkbox type=checkbox onclick='a($a)' value=checkbox>";
    ?>
    这样可以吧?
      

  5.   

    <input name=checkbox type=checkbox onclick="window.frames.rpc.location='check.php?par=a'" value=checkbox>
    <iframe name='rpc' width=0 height=0>
    </iframe>
    --------------------------
    check.php
    <?php
    aa($_GET['par']);
    function aa($a)
    {
      echo "<javascript>alert('".$a."')</javascript>";
    }?>