时间:2021-07-01 10:21:17 帮助过:2人阅读
(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>'; ?>
本文讲解了js和php嵌套,更多相关内容请关注Gxl网。
相关推荐:
js阻止默认事件与js阻止事件冒泡示例分享 js阻止冒泡事件
js函数常见的写法以及调用方法
原生JS的AJAX读取json全过程
以上就是js和php嵌套的详细内容,更多请关注Gxl网其它相关文章!