我在 javascript 中有这个循环数据。我想为每个值放置 html css 和 php。
var html = '';
$.each(data, function(name, value) {
html += value.email + "<br />" + value.content + "<br />";
});
$('#sidebarColumn').html(html);
这里我只是列出了一些值。可以说我想要
<span class="userEmail">value.email<span>
<div class="userContent">value.content</div>
<img src="<?php echo base_url() ?> value.picture" />
我如何将它们放在 JS 中或有其他方法使代码可读?
注意* 我在这里使用 .html() 是因为我想替换 #sidebarColumn 以前的数据并将循环数据放在那个 div 中
最佳答案
你可以像这样在 <script> 标签中编写 php,如果你正在寻找的话
<script type="text/javascript">
var baseUrl = '<?php echo $this->baseUrl() ?>';
var someVariable = '<?php
//some more php here
?>';
</script>
关于jquery - 如何在 javascript (Jquery) 中放置 html css php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12427011/