【发布时间】:2012-12-07 08:09:04
【问题描述】:
如何在 jquery/javascript 上插入 php?例如
php
$tot =4;
javascript
$(function()
if( can put php here? )
eg : if( <?php tot > 4 ?> )
我想把php放在'if语句'中,可以吗?
【问题讨论】:
如何在 jquery/javascript 上插入 php?例如
php
$tot =4;
javascript
$(function()
if( can put php here? )
eg : if( <?php tot > 4 ?> )
我想把php放在'if语句'中,可以吗?
【问题讨论】:
试试:
$(function() {
if(<?=$tot?> > 4) {
[...]
}
});
<?=$tot?> 部分将有效地 echo javascript 代码中的 $tot 变量。请注意,如果 $tot 在转换为字符串时计算为 '',则可能会在 javascript 代码中产生语法错误。
【讨论】:
您可以使用if (<?php echo $tot; ?> > 4)
【讨论】: