Is it okay to use PHP inside a jQuery script?

前端 未结 7 1461
误落风尘
误落风尘 2021-02-20 03:56

For example:

$(document).ready(function(){
    $(\'.selector\').click(function(){
        
    });
});
         


        
7条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-20 04:21

    It won't slow down the page; the PHP runs on the server and emits text which is sent to the browser, as on any PHP page. Is it bad practice? I wouldn't say "bad" necessarily, but not great. It makes for messy code - in the event where I need to do something like this, I usually try to break it up, as in:

    
    

提交回复
热议问题