您的位置:首页 > Web前端 > JQuery

Jquery 代码中插入php代码段并展示出来

2017-08-20 17:36 387 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Demo</title>

<style type="text/css">
#ljbutton {
background-color: #009A31;
width:220px;
cursor:pointer;
color: #FFFFFF;
font-weight: bold;
text-align:center;
padding:5px;
}
.sent {
display:none;
margin-bottom:5px;
font-family: Verdana;
font-size: 14px;
float:left;
color: #009A31;
}
</style>

<script src="http://open.mobile.qq.com/sdk/qqapi.js?_bid=152"></script>
<script src="http://imgcache.gtimg.cn/club/platform/lib/seajs/sea-with-plugin-2.2.1.js?_bid=250&max_age=2592000" id="seajsnode"></script>
<!-- 百度的jquery-->
<script type="text/javascript" src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<!-- 七牛云jquery -->
<!-- <script type="text/javascript" src = "https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> -->
<!-- 插入php 段落 -->
<?php
$test; $temp; $number = 1;
foreach ($_SERVER as $name => $value) {
$test = $number.". ".$name.":".$value;
echo $test."<br>";//换行
$number = $number + 1;
}
?>
<!-- <h1>It works! <?php phpinfo(); ?>></h1> -->

<script type="text/javascript">
var ljurl = 'https://raw.githubusercontent.com/robinson911/robinson911/master/ljweibo.json'

$(function() {
$('#ljbutton').click(function(){
if($.trim($('#ljbutton').text()) == '点击我')
{
$('#ljbutton').text('还原')
}
else{
$('#ljbutton').text('点击我')
}
// alert($('#ljbutton').text())

//eval可以把字符串转化为本地的json对象去执行
// var ljTes = "alert('hello eval')"
// eval(ljTes)
var ljdata = "<?php
$test; $temp; $number = 1;
foreach ($_SERVER as $name => $value) {
$test = $number.". ".$name.":".$value;
echo $test.'\r\n';
$number = $number + 1;
}
?>" ;
// 将php的信息用弹框展示出来
alert(ljdata)
// 将php的信息用label展示出来
$('#label').text(ljdata)
});
});
</script>
</head>

<body>
<h1>It works!</h1>
<div id="ljbutton">
点击我
</div>

<div id ="label">
ceddfff
</div>
</body>

</html>


在浏览器中输入:http://localhost/JSPhp.php 回车
效果图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: