内联 PHP 停止使用 if 函数和 javascript
我有一个 wordrpress 网站,使用一个名为 Inline PHP 的插件工作了大约 2 年。这是一个曾经有效的缩短版本:
<exec>
$levels = array('Level 3','Level 1','Level 2');
if (in_array("Level 3", $levels)) {
echo "<script language=javascript>getlevel('http://www.my-site.com/my-training/level-3/')</script>";
}
</exec>
现在不再有效,我不明白为什么。
我已经分别尝试了每个组件:
<exec>
$levels = array('Level 3','Level 1','Level 2');
echo implode(' ', $levels);
</exec>
写入正确的数组条目,并
<exec>
$levels = array('Level 3','Level 1','Level 2');
if (in_array("Level 3", $levels)) {
echo "yes";
</exec>
返回“是”(如果我使条件失败,则返回“否”),最后:
<exec>
echo "<script language=javascript>getlevel('http://www.my-site.com/my-training/level-3/')</script>";
</exec>
按预期重定向到 3 级页面。
问题似乎是当我将 javascript 嵌套在 if 条件中,它只是停留在该页面上 - 并且不在页面上呈现任何内容。
任何帮助,将不胜感激
I've had a wordrpress site working for about 2 years using a pluggin called Inline PHP. This is a shortened version that used to work:
<exec>
$levels = array('Level 3','Level 1','Level 2');
if (in_array("Level 3", $levels)) {
echo "<script language=javascript>getlevel('http://www.my-site.com/my-training/level-3/')</script>";
}
</exec>
This no longer works, and I can't figure out why.
I've tried each component individually:
<exec>
$levels = array('Level 3','Level 1','Level 2');
echo implode(' ', $levels);
</exec>
writes the correct array entries, and
<exec>
$levels = array('Level 3','Level 1','Level 2');
if (in_array("Level 3", $levels)) {
echo "yes";
</exec>
returns 'yes' (and no if I make the conditional fail), and finally:
<exec>
echo "<script language=javascript>getlevel('http://www.my-site.com/my-training/level-3/')</script>";
</exec>
redirects to the level-3 page as expected..
The problem seems to be when I am nesting the javascript in the if conditional and it's just staying on that page - and not rendering anything on the page.
ANY help, would be greatly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,它成功打印
到屏幕显示但页面未按预期重定向?
这似乎是 getlevel 函数的问题。按 12 查看控制台是否有错误。
So, it successfully prints
<script language=javascript>getlevel('http://www.my-site.com/my-training/level-3/')</script>
to the screen but the page doesn't redirect as expected?This seems to be a problem with the getlevel function. Press 12 and see if there are any console errors.