使用PHP打印功能时,在JQuery / JavaScript中引用

时间:2011-07-14 09:36:58

标签: php javascript jquery quotes

我正在尝试调试某人的代码并且遇到了一个新手错误。

现在虽然这可以在Xserve上运行(或者至少它可以忽略它),但是当在Linux服务器上运行时,它拒绝合作并将一个功能降低。

我很确定我需要做的是解决引号:引号的范围似乎是错误的 - 第一个双引号链接到第三个,第二个引用第四个。任何想法都非常欢迎!

<?php foreach ($years as $id => $title) : ?>
$("#<?php print $id ?>_both").click(function() {
$(".<?php print $id ?>.g, .<?php print $id ?>.b")
.attr("checked", $("#<?php print $id ?>_both").attr("checked"));
});
<?php endforeach; 

1 个答案:

答案 0 :(得分:1)

报价看起来不错(糟糕,但没关系)。你确定你没有错过结束php(最后一行):

<?php foreach ($years as $id => $title) : ?>
$("#<?php print $id ?>_both").click(function() {
$(".<?php print $id ?>.g, .<?php print $id ?>.b")
.attr("checked", $("#<?php print $id ?>_both").attr("checked"));
});
<?php endforeach; ?>