简体   繁体   English

如何将这个php标签插入jQuery?

[英]How do I insert this php tag into jQuery?

I am trying to figure out how to insert a php tag in between the opening and closing div tags below. 我试图弄清楚如何在下面的开始和结束div标签之间插入php标签。 Can anyone help me understand how to insert <?php the_field('200_200_1', 'option'); ?> 谁能帮助我了解如何插入<?php the_field('200_200_1', 'option'); ?> <?php the_field('200_200_1', 'option'); ?> in there? <?php the_field('200_200_1', 'option'); ?>在那里?

jQuery(document).ready(function($){

    $('<div class="video_gallery_ad"></div>').appendTo('#avs_gallery');

});

Edit: This is a JS file. 编辑:这是一个JS文件。

Edit2: Since this won't work with a JS file, I moved it into my functions.php file (using WordPress). Edit2:由于这不适用于JS文件,因此我将其移至我的functions.php文件中(使用WordPress)。 Below is the snippet I have in my functions.php file. 以下是我的functions.php文件中的片段。 Is there anything wrong with this code? 这段代码有什么问题吗?

jQuery(document).ready(function($){

    $('<div class="video_gallery_ad"><?php the_field('200_200_1', 'option'); ?></div>').appendTo('#avs_gallery');

}); 

You can try with: 您可以尝试:

$('<div class="video_gallery_ad"><?php the_field('200_200_1', 'option'); ?></div>').appendTo('#avs_gallery');

But it is VERY risky. 但这非常冒险。 Isn't it better to render render output of this function in some hidden div and after that load its content into #avs_gallery ? 在某个隐藏的div中渲染此函数的渲染输出是否更好,然后将其内容加载到#avs_gallery

And JS: 和JS:

$('#hiddenAdv').show().appendTo('#avs_gallery');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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