PHP与jQuery的超级组合

这两天学了学PHP,发现PHP真是个好东西,免费开源又简单,就一个字:爽! 学完了PHP的基本语法想找个PHP的模板学学,baidu,google了半天,发现了smarty,phplib等将近25个引擎,可真不少啊…… 到底要学哪个呢? 别忙,停停再说吧,因为我有了个新的想法: 用PHP加上前阵子学的jQuery怎么样呢?小试一把....
1.jquery.js 此处下载: http://code.google.com/p/jqueryjs/
2.目录结构:
   html目录中存放html.html文件
   inc目录中存放 jQuery.php文件
   js目录中存放jQuery.js文件
   主目录下存放html.php文件
3.内容:
   html.html文件:

<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>PHP+jQuery组合测试</title><style>h5{color:#CC3333;margin:0px;padding:0px;}#test{    font:bold 14px;    color:#003366;    cursor:pointer;}</style></head><body><h5>PHP+jQuery超级组合实验2:会话与参数传递</h5><hr/><div id="user"></div><form method="post" action="html.php" id="form1" name="form1"><label for="name"><input id="name" name="name" maxlength="20"/><br/><label for="age"><input id="age" name="age" maxlength="3"/><br/><input type="submit" name="submit" value="提交"/></form><h5>PHP+jQuery超级组合实验1:简单测试</h5><hr/><div id="test">Hello World! Click me please!</div><p id="pinfo">hello.</p></body></html>


jQuery.php

<?phpfunction jQinit($html){    if($html != NULL && $html != "")    {        $html=file_get_contents($html);        echo $html;        }    /*echo "<script language='javascript' src='js/jQuery.js'></script>";*/    $jqstr=file_get_contents("js/jQuery.js");    echo "<script language='javascript'>";    echo $jqstr;    echo "</script>";}//参数$jstr:jQuery脚本字符串;$html模板页面路径.function jQuery($jstr){//jQuery脚本$jQuery=<<<EOT<script language="javascript"> $("document").ready(function(){    $jstr; });</script>    EOT;//输出具体jQuery内容echo $jQuery;}?>


 

 html.php

<?php session_start();?><?php//引用jQuery模块require("inc/jQuery.php");//初始化本页对应的htmljQinit("html/html.html");?><?php//PHP+jQuery超级组合实验2:会话与参数传递$jq="";$name="";$age="";if(
{1}

POST["name"] != "" &&
{1}

POST["age"] != ""){ $name=
{1}

POST["name"]; $age=
{1}

POST["age"];
{1}

SESSION["name"] = $name;
{1}

SESSION["age"] = $age;}if(
{1}

SESSION["name"] != "" &&
{1}

SESSION["age"] != ""){$jq=<<<EOT $("#user").text("您的名字:{
{1}

SESSION['name']} 年龄:{
{1}

SESSION['age']}");EOT;//调用jQueryjQuery($jq);}?><?php//PHP+jQuery超级组合实验1:简单测试$info="确实不错!";$jQuery=<<<EOT //alert("测试成功!"); $("#test").click(function(){ alert("拉登,您好."); }); $("#pinfo").text("今天天气不错啊!{$info}");EOT;//调用jQueryjQuery($jQuery);?>

 

效果预览:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值