使用PHP嵌入的jQuery .html()

时间:2015-07-16 20:08:55

标签: javascript php jquery

我需要在页面中添加一些html内容。我可以这样做:

$("#followUser").html('<label id="followUser"><button class="btn btn-primary" id="followUserButton"><i class="fa fa-check"></i> Unfollow</button></label>');

但我需要动态更改按钮文本,如

$("#followUser").html('<label id="followUser"><button class="btn btn-primary" id="followUserButton"><i class="fa fa-check"></i> <?=$lng['2buttonFollow'];?></button></label>');

第二个是我的解决方案,但它不起作用。任何的想法?如何通过jquery添加一些php变量?

问题解决后编辑: 它是关于回声部分的。当我尝试使用 echo 的简短方法时,它会导致javascript失败。 实际上我的解决方案是真的,只是改为 echo

1 个答案:

答案 0 :(得分:-1)

你只是在php标签内传递php变量$lng['2buttonFollow'];。使用echo显示变量的值。

$("#followUser").html('<label id="followUser"><button class="btn btn-primary" id="followUserButton"><i class="fa fa-check"></i> <?php echo $lng['2buttonFollow'];?></button></label>');