<php变量可以赋值给js,但是反过来不行,js变量无法直接赋值给php。先运行php,运行之后再赋值给php。>
js拼接html时,用到js变量,用单引号引起来,然后+号拼接。
<script>
<?php $ic = C('IMAGE_CONFIG'); ?>
var picView = "<?php echo $ic['viewPath']; ?>";
$("#cart_list").mouseover(function () {
$.ajax({
url:"<?php echo U('Cart/ajaxCartList'); ?>",
data:"",
dataType:"json",
type:"GET",
success:function (msg) {
//拼出的HTML放到页面中
var html = "<table>";
$(msg).each(function (k,v) {
html += "<tr>";
html += '<td><img width="50" src="'+picView+v.mid_logo+'" /></td>';
html += '<td>'+v.goods_name+'</td>';
html += "</tr>";
});
html += "</table>";
$("#cart_div_list").html(html);
}
});
});
</script>
网友评论