gpt4 book ai didi

php - 从 php echo 调用 javascript 图像不透明度函数

转载 作者:行者123 更新时间:2023-11-28 16:30:38 25 4
gpt4 key购买 nike

我已经做到了,当您将光标悬停在图像按钮上时,它开始淡出,当您将光标移出时,它会恢复到原始的不透明度。问题是,当我在正文内容周围添加 php 标签并回显表格时,它不再起作用。感谢您提前提供帮助。

代码如下:

<html>
<head>
<script type="text/javascript">
function SetOpacity(elem, opacityAsInt)
{
var opacityAsDecimal = opacityAsInt;

if (opacityAsInt > 100)
opacityAsInt = opacityAsDecimal = 100;
else if (opacityAsInt < 0)
opacityAsInt = opacityAsDecimal = 0;

opacityAsDecimal /= 100;
if (opacityAsInt < 1)
opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0

elem.style.opacity = opacityAsDecimal;
elem.style.filter = "alpha(opacity=" + opacityAsInt + ")";
}

function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps)
{
var steps = Math.ceil(fps * (time / 1000));
var delta = (toOpacity - fromOpacity) / steps;

FadeOpacityStep(elemId, 0, steps, fromOpacity, delta, (time / steps));
}

function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, delta, timePerStep)
{
SetOpacity(document.getElementById(elemId), Math.round(parseInt(fromOpacity) + (delta * stepNum)));

if (stepNum < steps)
setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ");", timePerStep);
}

</script>
</head>


<body>
<?php

echo"
<form action='opacity.php' method='post'>

<input type='image' name='blue' id='ImgAkxl2' value='blue' src='streetfighter.jpg'
onmouseover='FadeOpacity('ImgAkxl2', 100, 70, 250 , 24)'
onmouseout ='FadeOpacity('ImgAkxl2', 70, 100, 250 , 24)'



/>
</form>


";

?>
</body>
</html>

最佳答案

您需要转义 onmouseover 和 onmouseout 事件中的内部引号

<input type='image' name='blue' id='ImgAkxl2' value='blue' src='streetfighter.jpg'
onmouseover='FadeOpacity(\'ImgAkxl2\', 100, 70, 250 , 24)'
onmouseout ='FadeOpacity(\'ImgAkxl2\', 70, 100, 250 , 24)'
/>

关于php - 从 php echo 调用 javascript 图像不透明度函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6166231/

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