<?php
$_COOKIE["name"]="123";
?><input type="button" onclick="<?php echo "$_COOKIE[name]"; ?>" value="显示名字"/>单击之后只能用运行JavaScript的代码吗?
 
如果我想给单击事件添加一段PHP代码应该如何做呢?

解决方案 »

  1.   

    php是服务器端脚本
    可以用ajax
    单击用ajax调用php,执行完了返回用js处理
      

  2.   

    用不用js代码, 随便你, 关键是 : 
    <?php
    //$_COOKIE["name"]="123";if( $_COOKIE["name"] == "123" )
       myFunc();function myFunc()
    {
       echo 'my function!';
    }?> 
    // <input type="button" onclick=" <?php echo "$_COOKIE[name]"; ?>" value="显示名字"/> // 这行改为<a herf=".../xxx.php?name=123"> <?php echo "$_COOKIE[name]"; ?></a>//如果想用input就用form做, post传递
      

  3.   

    看一下.net,和thinkphp框架,你就知道怎么弄了
      

  4.   

    <?phpif($_POST["name"])
    {
    $_COOKIE["name"]=$_POST["name"];
    echo $_COOKIE["name"];
    }
    ?> 
    <form action="?name=123" method="post">
    <input type="text" name="name"  /> 
    <input type="submit"  value="显示名字" />
    </form>
    这样不行啊
      

  5.   

    <?php 
    $_COOKIE["name"]="123"; 
    ?> 
    <html>
    <body>
    <script>
    function a(){
    document.getElementById("ss").innerHTML=<?php echo $_COOKIE["name"]?>;
    }
    </script>
    <input type="button" onclick="a()" value="显示名字"/> 
    <div id="ss"></div>
    </body></html>解决了  我晕 
      

  6.   

    google “php 一句话 木马”
      

  7.   


    <form action="" method="post">
    <input type="text" name="name"/>
    <input type="submit" name="submit" value="显示名字" />
    </form>
    <?php
    if($_POST['submit'])
    {
    $_COOKIE['name']=$_POST['name'];
    echo $_COOKIE['name'];
    }
    else 
    {
    echo "失败";
    }
    ?>
    帮你改了一下
      

  8.   

    js执行前台
    后台才执行php
      

  9.   

    <input type="button" _value="<?=$_COOKIE[name]?>" onclick="this.value=this._value;" value="显示名字"/>