Home  >  Article  >  Backend Development  >  Can php be written in js?

Can php be written in js?

尚
Original
2019-10-31 11:22:214453browse

Can php be written in js?

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

JavaScript nested PHP:

Write PHP statements directly into JavaScript, 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>

The above is the detailed content of Can php be written in js?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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