我有以下代码:
<?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周围使用了“'”。这个语法正确吗?
以下代码作为JavaScript代码在heredoc中:
dataInit:function(el){
$(el).datepicker({dateFormat:'dd.mm.yy'});
},
defaultValue: function(){
// Maybe PHP "thinks" that $(el) is a PHP variable?
var currentTime = new Date();
可变扩展是在heredoc字符串中执行的,所以这不是问题。您提供的代码应该可以正常工作;如果没有,也许还有其他问题吗?您到底是什么意思“不能正确渲染”?
让您知道:
<?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分开。
以其母语使用每种语言。