我想用 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/