js and php nesting

jacklove
Release: 2023-04-01 11:50:01
Original
6389 people have browsed it

JavaScript and PHP can be nested in each other, provided that JavaScript is written in a file with the .php suffix.

# (1) Javascript nested PHP:

# directly in javascript PHP statements, such as:

<script type="text/javascript">
  BUI.use(&#39;bui/grid&#39;,function (Grid) {
    var data = [//表单内容信息
            <?php
		foreach($slice_rows as $key=>$val){
		echo "{id:&#39;".$val[&#39;id&#39;]."&#39;,imgpath:&#39;".$val[&#39;imgpath&#39;]."&#39;,introduction:&#39;".$val[&#39;introduction&#39;].
               "&#39;,linkpath:&#39;".$val[&#39;linkpath&#39;]."&#39;,date:&#39;".$val[&#39;date&#39;]."&#39;},";
	    }
	
	       echo "{id:&#39;1112&#39;,imgpath:&#39;李四&#39;,introduction:&#39;this is a test&#39;,linkpath:&#39;#&#39;,date:&#39;date2&#39;}";
	   ?>
	],
 
        grid = new Grid.SimpleGrid({
          render : &#39;#grid&#39;, //显示Grid到此处
          width : 950,      //设置宽度
          columns : [//表单头部信息
            {title:&#39;编号&#39;,dataIndex:&#39;id&#39;,width:80},
            {title:&#39;图片路径&#39;,dataIndex:&#39;imgpath&#39;,width:100},
			{title:&#39;简介&#39;,dataIndex:&#39;introduction&#39;,width:200},
			{title:&#39;链接地址&#39;,dataIndex:&#39;linkpath&#39;,width:100},
            {title:&#39;上传日期&#39;,dataIndex:&#39;date&#39;,width:100}
          ]
        });
      grid.render();
      grid.showData(data);
  });
  
</script>
Copy after login

(2) PHP nesting JavaScript:

<?php
		
	echo &#39;<script type="text/javascript">&#39;;
	echo " BUI.use(&#39;bui/grid&#39;,function (Grid) {";
	//表单的数据内容
	echo &#39;var data = [&#39;;
	foreach($slice_rows as $key=>$val){
		echo "{id:&#39;".$val[&#39;id&#39;]."&#39;,imgpath:&#39;".$val[&#39;imgpath&#39;]."&#39;,introduction:&#39;".$val[&#39;introduction&#39;].
                     "&#39;,linkpath:&#39;".$val[&#39;linkpath&#39;]."&#39;,date:&#39;".$val[&#39;date&#39;]."&#39;},";
	}
	
	echo "{id:&#39;1112&#39;,imgpath:&#39;李四&#39;,introduction:&#39;1349622209547&#39;,linkpath:&#39;#&#39;,date:&#39;date2&#39;}";
	
	echo &#39;],&#39;;
	//表单的头部信息
	echo "
	 grid = new Grid.SimpleGrid({
          render : &#39;#grid&#39;, //显示Grid到此处
          width : 950,      //设置宽度
          columns : [
            {title:&#39;编号&#39;,dataIndex:&#39;id&#39;,width:80},
            {title:&#39;图片路径&#39;,dataIndex:&#39;imgpath&#39;,width:100},
			{title:&#39;简介&#39;,dataIndex:&#39;introduction&#39;,width:200},
			{title:&#39;链接地址&#39;,dataIndex:&#39;linkpath&#39;,width:100},
            {title:&#39;上传日期&#39;,dataIndex:&#39;date&#39;,width:100}
          ]
        });
	
	";
	echo &#39;  grid.render();
			grid.showData(data);
			});
  &#39;;
	
	
	//echo &#39;alert("this is a test")&#39;;
	echo &#39;</script>&#39;;
	
?>
Copy after login

This article explains js and php nesting , please pay attention to php Chinese website for more related content.

Related recommendations:

js prevent default events and js prevent event bubbling examples share js prevent bubbling events

js common functions The writing method and the calling method

The whole process of reading json by AJAX in native JS

The above is the detailed content of js and php nesting. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template