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
<?php function 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(<pre class="php" name="code">{1}</pre><br> POST[ "name" ] != "" && <pre class = "php" name= "code" >{1}</pre><br> POST[ "age" ] != "" ){ $name =<pre class = "php" name= "code" >{1}</pre><br> POST[ "name" ]; $age =<pre class = "php" name= "code" >{1}</pre><br> POST[ "age" ]; <pre class = "php" name= "code" >{1}</pre><br> SESSION[ "name" ] = $name ; <pre class = "php" name= "code" >{1}</pre><br> SESSION[ "age" ] = $age ;} if (<pre class = "php" name= "code" >{1}</pre><br> SESSION[ "name" ] != "" && <pre class = "php" name= "code" >{1}</pre><br> SESSION[ "age" ] != "" ){ $jq =<<<EOT $( "#user" ).text( "您的名字:{<pre class=" php " name=" code">{1}</pre><br> SESSION[ 'name' ]} 年龄:{<pre class = "php" name= "code" >{1}</pre><br> SESSION[ 'age' ]} ");EOT;//调用jQueryjQuery($jq);}?><?php//PHP+jQuery超级组合实验1:简单测试$info=" 确实不错! ";$jQuery=<<<EOT //alert(" 测试成功! "); $(" #test ").click(function(){ alert(" 拉登,您好. "); }); $(" #pinfo ").text(" 今天天气不错啊!{ $info }");EOT;//调用jQueryjQuery( $jQuery );?> <pre></pre> <p> </p> <p>效果预览:<br> <img src= "http://hi.csdn.net/attachment/201108/9/0_1312867256CjnL.gif" alt= "" ></p> ?> |
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦