gpt4 book ai didi

javascript - 混合代码错误

转载 作者:行者123 更新时间:2023-12-03 12:39:56 26 4
gpt4 key购买 nike

好的,我的网站上有一个基本的一体化用户个人资料页面,如下所示:

<?php

if($_GET['p']=='pb'){

echo '<p>pb</p>';

}elseif($_GET['p']=='example2'){

echo '<p>Example Two';

}elseif($_GET['p']=='example1'){

echo '<p>Example One';

}else{
echo '<h3>Page not defined&#59 error!</h3>';

}

?>

不过,当我尝试添加 onclick="location.href='' 时,我遇到了一些内联 javascript 的问题,php 混淆了它。我尝试在前面和后面添加\',但它没有'似乎不起作用,这是我所拥有的:

<?php

if($_GET['p']=='pb'){

echo '<p>pb</p>';

}elseif($_GET['p']=='example2'){

echo '
<h1>Example Link One</h1>
<p>You clicked Example Link One!</p>
<table border="0" cellspacing="15" width="100%">
<tr>
<td bgcolor="grey" onclick="location.href=\''/media/profiles/person/'\'">
<p>HOME</p>
</td>
</tr>
</table>';

}elseif($_GET['p']=='example1'){

echo '
<h1>Example Link One</h1>
<p>You clicked Example Link One!</p>
<table border="0" cellspacing="15" width="100%">
<tr>
<td bgcolor="grey" onclick="location.href=\''/media/profiles/person/'\'">
<p>HOME</p>
</td>
</tr>
</table>';

}else{
echo '<h3>Page not defined&#59 error!</h3>';

}

?>

但我仍然遇到一些错误,包括:- 使用未定义的常量媒体 - 假定为“媒体”-警告:除以零-注意:使用未定义的常量配置文件 - 假定的“配置文件”-注意:使用未定义的常量 person - 假定“person”依此类推。

我知道它与什么有关,但我该如何解决它?

最佳答案

为什么不直接关闭 PHP 标签呢?

<?php

if($_GET['p']=='pb'){

echo '<p>pb</p>';

}elseif($_GET['p']=='example2'){

?>
<h1>Example Link One</h1>
<p>You clicked Example Link One!</p>
<table border="0" cellspacing="15" width="100%">
<tr>
<td bgcolor="grey" onclick="javascript:location.href='/media/profiles/person/'">
<p>HOME</p>
</td>
</tr>
</table>
<?php

}elseif($_GET['p']=='example1'){

?>
<h1>Example Link One</h1>
<p>You clicked Example Link One!</p>
<table border="0" cellspacing="15" width="100%">
<tr>
<td bgcolor="grey" onclick="javascript:location.href='/media/profiles/person/'">
<p>HOME</p>
</td>
</tr>
</table>
<?php

}else{
echo '<h3>Page not defined&#59 error!</h3>';

}

?>

此外,在应用程序中使用设计模式会更优雅 - 如果您坚持使用当前使用的“设计模式”,此应用程序将成为更新和维护的负担。

关于javascript - 混合代码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23569547/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com