php - 如何在php中编写html代码?

标签 php javascript html

我想用 php 编写一些 html 代码。在此 html 代码中,我调用了一个 javascript 函数。但是在调用函数时出现问题。我认为问题出在引号上,但我无法解决。

这是我想放入 php 中的 html 代码。

<table>
 <tr>
 <a href="javascript:chng('img');"><img src="s.png" name="img"></a> 
 </tr>
</table>

这是我的javascript代码;

<script type="text/javascript">
img1 = "s.png";
img2 = "k.png";
function chng(c_img) {
if (document[c_img].src.indexOf(img1)!= -1) document[c_img].src = img2;
else document[c_img].src = img1;
} 

</script>

我如何在 php 代码中编写此 html?

谢谢

最佳答案

<?php

// your php code

?>

<table>
 <tr>
 <a href="javascript:chng('img');"><img src="s.png" name="img"></a> 
 </tr>
</table>

<?php

// your php code

?>

<script type="text/javascript">
img1 = "s.png";
img2 = "k.png";
function chng(c_img) {
if (document[c_img].src.indexOf(img1)!= -1) document[c_img].src = img2;
else document[c_img].src = img1;
} 

</script>

<?php 

关于php - 如何在php中编写html代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5804055/

相关文章:

php - 确保所有标签都关闭 php

PHP获取用户ip,真的靠谱吗?

javascript - 如何使用浏览器窗口的大小?

javascript - owl-carousel - 如何使用下一个点滑到第三张幻灯片 - .owl-dot :Active

Javascript - 比较两个数组对象并附加值

javascript - CSS:Hover 的文本问题因为溢出而被隐藏:隐藏?

php - 如何避免多对多查询中的 "Using temporary"?

php - Laravel - 将控制台输出写入日志文件

php - 如何以矩阵模式访问 MySQL 表中的值?

javascript - 在 Sweet alert 2 中传递 PHP 变量