简体   繁体   中英

Echo html and PHP in jQuery syntax

我如何在jQuery中回显以下HTML和PHP以使其呈现为html?

<script src="<?php bloginfo('template_directory'); ?>/js/carousel.js"></script>

You can save it inside a variable like

var script = "<?php bloginfo('template_directory'); ?>" + "/js/carousel.js";

Watch out for the quote you use.

Try the below code.

$('head').append('<script src="<?php bloginfo('template_directory'); ?>/js/carousel.js"></script>')

It will add the code at the end of head tag. Assuming all your jquery library available in head tag

Note: It will work only if you write this code inside a php file

也许这就是你想要的

<script src="<?php echo bloginfo('template_directory'); ?>/js/carousel.js"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM