[英]how to add javascript inside php file with html content?
I have a Wordpress plugin. 我有一个Wordpress插件。 inside this plugin there is a php file.(for example name.php) this php file contains some codes which they are inside this code: 在此插件中有一个php文件。(例如name.php),此php文件包含一些位于此代码中的代码:
<script type="text/html" id="tmpl-dokan-single-variations">
//codes
</script>
Now I want to add some Javascript codes and I've tried this code: 现在,我想添加一些Javascript代码,并尝试了以下代码:
<script type="text/html" id="tmpl-dokan-single-variations">
<script type="text/javascript">
//mycodes
</script>
//codes
</script>
Also I've tried echo script but it doesn't work either. 我也尝试了echo脚本,但是它也不起作用。 Please tell me how can I add some javascript code inside this file? 请告诉我如何在此文件中添加一些javascript代码?
There is no way to include the raw string </script>
inside a script element. 无法将原始字符串</script>
包含在script元素中。
You would need to find some alternative representation of it (such as <!-- TEMPLATE: SCRIPT END TAG -->
and then modify the code (which is presumably JavaScript) that reads the value of the <script type="text/html">
element so it can replace that alternative representation with the end tag you actually want. 您将需要找到它的一些替代表示形式(例如<!-- TEMPLATE: SCRIPT END TAG -->
,然后修改读取<script type="text/html">
的值”的代码(可能是JavaScript)。 <script type="text/html">
元素,以便可以用您实际想要的结束标记替换该替代表示。
I dont know what your php file looks like but you can echo your script like this 我不知道您的php文件是什么样子,但是您可以像这样回显脚本
<?php
echo '
<script>
// your code here
</script>
';
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.