简体   繁体   中英

jQuery's replaceWith() method changes PHP code to HTML comment

In a click event handler I would like to change a div element. In this element is also HTML and PHP code.

After the change the PHP code is in a HTML comment. What I can do to fix this?

在此处输入图片说明

Here is a short version of my code:

$("#replaceCat1").click(function(){
  $("div.boxcontent2").replaceWith("<div class='boxcontent1'> <?php print_string('placehoder1', 'theme_'.$theme->name); ?></div> ");
});

Edit:

i design a theme. In this theme gives it 4 boxes with information from the backend. My php code is at the moment only a placeholder. later I include the backend php code. In my theme, gives a dropdown menu. In this gives 4 categories, when you select one, then I would like that the 3 of the 4 boxes switch die information and the design. That is the plan with the code.

The code comes from the .js file. It is better to load the code from a php file and include it with .load() ?

If you want javascript to be able to dynamically include something that comes from php, then you will need to look into AJAX . Probably jQuery's $.ajax() function will be enough.

If you are simply wanting the text from PHP to appear once in the javascript, you will need to run the javascript through php.

Assuming that you actually have a php server an that your project is running on this server, a quick, ugly hack that will allow you to do this is to rename your .js file into a .php file, and include() it between a pair of script tags.

<script>
Include('filthy_hack.php');
</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