就象嵌套PHP和HTML一样的 啊

解决方案 »

  1.   

    你的意思是象php控制html一样,是吗?
    你可以先写好javascript的函数代码,然后再用php的if........等产生javascript调用javascript的函数呀。
      

  2.   

    可以用php的echo来输出你要的javascript代码。
      

  3.   

    现在还用PHP,一年我开发的一个项目,给你个片段吧,里面有数据库、JAVASCRIPT、HTML提交的语句!
    <?
    require ("config.php3");
    ?>
    <?
    if($submit)
    {
    //echo $action;//if($action=='update')
    if($id)
    {$query="update banner_place set adv_plc='$adv_plc',size='$size',description='$description' where id=$id";   $message="update banner place ";}else 
    {
    $query="insert into banner_place (adv_plc,size,description) values ('$adv_plc','$size','$description')";
       $message="added banner place " ;
     
     }
      
       $my_res = mysql_db_query($phpAds_db, $query) or mysql_die();
            //   Header("Location: banner.php3?pageid=$pageid&message=".urlencode($message));
           //   Header("Location: banner.php3");
    echo "<script>window.location.href ='admin.php3?pageid=$pageid&message=$message'</script>";exit();
     }
       
        ?><?
    page_header("$phpAds_name: $strBannerAdmin");
    ?>
    <table border="0" cellspacing="0" cellpadding="1" align="center" bgcolor="#000099">
      <tr>
        <td>
          <table border="0" align="center" bgcolor="#FeeeeF" cellspacing="0" cellpadding="5">
            
         
            <tr>
      <td bgcolor="#CCCCCC">
     <a href=admin.php3?pageid=admin>Home</a> <img src=/AdServer/arrow.gif width=8 height=7> 
     AddBannerPlace
      </td>
            </tr>
            <tr>
      <td width=500>
    <?
    //if id not empty then update mode//$action="add";if($id)
    {
    //$action="update";
    $query_str="select * from banner_place where id=$id";
    $res=mysql_db_query($phpAds_db, $query_str) or mysql_die();
      $row = mysql_fetch_array($res);
    }?>
    <script language="JavaScript">
    <!--
    function CheckForm()
    {
    if (document.form.adv_plc.value == "" )
    {
    alert ("PLEASE INPUT PLACE_NAME!");
    return false;
    }var Letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    for (i=0; i < document.form.adv_plc.value.length; i++)
    {
    var CheckChar = document.form.adv_plc.value.charAt(i);
    CheckChar = CheckChar.toUpperCase();
    if (Letters.indexOf(CheckChar) == -1)
    {
    alert ("JUST CAN USE LETTER!");
    return false;
    }
    }}
    // -->
    </Script>  <form  action="<? echo $PHP_SELF."?id=$id";  ?>" name="form" method="POST" onSubmit="return CheckForm()">
        <table border="0" width="100%">
          <tr>
            <td width="50%"  bgcolor="#ECECFF">ADV Place</td>
            <td width="50%"  bgcolor="#ECECFF">
            <input type="text" name="adv_plc" size="27" value="<?if (isset($id)) echo $row[adv_plc];?>"></td>
          </tr>
           <tr>
            <td width="50%"  bgcolor="#ECECFF">Banner Size</td>
            <td width="50%"  bgcolor="#ECECFF">
            <input type="text" name="size" size="27" value="<?if (isset($id)) echo $row[size];?>"></td>
          </tr>
          <tr>
            <td width="50%"  bgcolor="#ECECFF">ADV Place Description</td>
            <td width="50%"  bgcolor="#ECECFF">
            <textarea rows="2" name="description" cols="26"><?if (isset($id)) echo $row[description];?></textarea></td>
          </tr>
        </table>
        <p align="center"><input type="submit" value="GO" name="submit"></p>
      </form>            </td>
            </tr>
            
      
          </table>
    <?
     page_footer();
    ?>