在jQuery脚本中使用PHP可以吗? [英] Is it okay to use PHP inside a jQuery script?

查看:95
本文介绍了在jQuery脚本中使用PHP可以吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

  $(document).ready(function(){
$('。selector ').click(function(){
<?php
// php code here here
?>
});
});

这会导致问题还是减慢页面速度?这是不好的做法吗?有什么重要的,我应该知道这与此有关吗?

谢谢!

解决方案

如果您试图用点击事件绑定一些PHP代码,那么这是不可能的,因为您尝试的方式是不可能的,PHP代码将在页面加载后立即执行,而无需等待点击事件。 b
$ b

如果您试图使用PHP生成最终的javascript或jquery代码,那么这就好了。


For example:

$(document).ready(function(){
    $('.selector').click(function(){
        <?php
        // php code goes here
        ?>
    });
});

Will this cause issues or slow down the page? Is this bad practice? Is there anything important that I should know related to this?

Thanks!

解决方案

If you are trying to bound some PHP code with the click event then this is impossible in the way you are trying and PHP code will be executed as soon as page load without waiting for a click event.

If you are trying to generate final javascript or jquery code using PHP then this is okay.

这篇关于在jQuery脚本中使用PHP可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆