JavaScript和PHP可以相互嵌套,条件是JavaScript写在以.php为后缀的文件里面。
(1) JavaScript嵌套PHP:
直接在JavaScript里面写入PHP语句,如:
<script type=\"大众text/javascript\"大众>
BUI.use('bui/grid',function (Grid) {
var data = [//表单内容信息
<?php
foreach($slice_rows as $key=>$val){
echo \"大众{id:'\"大众.$val['id'].\"大众',imgpath:'\"大众.$val['imgpath'].\公众',introduction:'\"大众.$val['introduction'].
\公众',linkpath:'\公众.$val['linkpath'].\"大众',date:'\"大众.$val['date'].\"大众'},\"大众;
}
echo \"大众{id:'1112',imgpath:'李四',introduction:'this is a test',linkpath:'#',date:'date2'}\"大众;
?>
],
grid = new Grid.SimpleGrid({
render : '#grid', //显示Grid到此处
width : 950, //设置宽度
columns : [//表单头部信息
{title:'编号',dataIndex:'id',width:80},
{title:'图片路径',dataIndex:'imgpath',width:100},
{title:'简介',dataIndex:'introduction',width:200},
{title:'链接地址',dataIndex:'linkpath',width:100},
{title:'上传日期',dataIndex:'date',width:100}
]
});
grid.render();
grid.showData(data);
});
</script>
(2)PHP嵌套JavaScript:
<?php
echo '<script type=\"大众text/javascript\"大众>';
echo \"大众 BUI.use('bui/grid',function (Grid) {\"大众;
//表单的数据内容
echo 'var data = [';
foreach($slice_rows as $key=>$val){
echo \公众{id:'\公众.$val['id'].\"大众',imgpath:'\"大众.$val['imgpath'].\"大众',introduction:'\"大众.$val['introduction'].
\"大众',linkpath:'\公众.$val['linkpath'].\"大众',date:'\"大众.$val['date'].\"大众'},\"大众;
}
echo \"大众{id:'1112',imgpath:'李四',introduction:'1349622209547',linkpath:'#',date:'date2'}\"大众;
echo '],';
//表单的头部信息
echo \"大众
grid = new Grid.SimpleGrid({
render : '#grid', //显示Grid到此处
width : 950, //设置宽度
columns : [
{title:'编号',dataIndex:'id',width:80},
{title:'图片路径',dataIndex:'imgpath',width:100},
{title:'简介',dataIndex:'introduction',width:200},
{title:'链接地址',dataIndex:'linkpath',width:100},
{title:'上传日期',dataIndex:'date',width:100}
]
});
\"大众;
echo ' grid.render();
grid.showData(data);
});
';
//echo 'alert(\公众this is a test\"大众)';
echo '</script>';
?>
推举:php做事器
以上便是js怎么跟php结合利用的详细内容,更多请关注其它干系文章!
更多技巧请《转发 + 关注》哦!