1

我有以下代码:

<?php
    if ($zweck == "buchhaltung") {
        echo <<<EOF
        <script type="text/javascript">
            jQuery(document).ready(function() {
            jQuery("#$grid_name").jqGrid({
                url: 'modules/mod_jqgrid/ex_get3.php?tb=$tb'
                .....
        </script>
EOF;
    };
?>

...似乎无法正确渲染。我们不能在 JavaScript 代码中的 heredoc 中使用 PHP 变量,就像我在倒数第二行使用它一样吗?

在最后一行,我在 PHP 变量 $tb 周围使用了“'”。这个语法正确吗?

以下代码在 heredoc 中作为 JavaScript 代码:

dataInit:function(el){
    $(el).datepicker({dateFormat:'dd.mm.yy'});
},
defaultValue: function(){

// Maybe PHP "thinks" that $(el) is a PHP variable?

var currentTime = new Date();
4

2 回答 2

1

变量扩展是在 heredoc 字符串中执行的,所以这不是问题。您提供的代码应该可以正常工作;如果没有,也许还有其他问题?你到底是什么意思“没有正确渲染”?

于 2011-03-16T11:47:41.310 回答
1

为了让您了解:

<?php
    if ($zweck == "buchhaltung"){
?>

<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery("#<?php echo $grid_name ?>").jqGrid({
            url: 'modules/mod_jqgrid/ex_get3.php?tb=<?php echo $tb?>',...

无需转义任何内容:只需将您的 JavaScript 代码与 PHP 分开即可。

以本地方式使用每种语言。

于 2011-03-16T11:56:37.273 回答