包含PHP代码的Javascript字符串变量 [英] Javascript string variable that contains PHP code

查看:88
本文介绍了包含PHP代码的Javascript字符串变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上只想使用JQuery将JavaScript变量附加到HTML div.但是,我需要将一些PHP代码附加为字符串,不需要执行它,而只需将其显示为普通的旧字符串即可.

I basically just want to append a javascript variable to an HTML div with JQuery. However I need to append some PHP code as a string, it doesn't need to execute it just needs to show up as a plain old string string.

以下代码似乎没有追加,因为我认为它仍被视为PHP语法.

The following code doesn't seem to append because I think it is still recognized as PHP syntax.

var script = '<?php wp_list_pages(); ?>';
divName.innerHTML = script;

任何帮助将不胜感激.

推荐答案

只是一个猜测...将php括号替换为HTML实体(& lt和& gt;),因此它不会被解释为PHP代码(如果您通过PHP运行包含JS的文件)或浏览器将其作为奇怪的HTML代码(浏览器将括号搜索为html标签,请记住...).

Just a guess... replace the php brackets with HTML entities (&lt; and &gt;) so it will not be interpreted as PHP code (if you run the file containing the JS through PHP) nor as strange HTML code (the browser searches for brackets as html tags, remember...) by the browser.

这篇关于包含PHP代码的Javascript字符串变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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