我已经做到这一点,当你将光标悬停在图像按钮上时,它会开始淡出,当你移出光标时,它会回到原始的不透明度。问题是,当我在正文中的内容周围添加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>
答案 0 :(得分:3)
您需要在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)'
/>
答案 1 :(得分:1)
onmouseover='FadeOpacity('ImgAkxl2', 100, 70, 250 , 24)'
onmouseout ='FadeOpacity('ImgAkxl2', 70, 100, 250 , 24)'
变为
onmouseover='FadeOpacity(\"ImgAkxl2\", 100, 70, 250 , 24)'
onmouseout ='FadeOpacity(\"ImgAkxl2\", 70, 100, 250 , 24)'
你的问题解决了! :)
在属性的值中使用相同类型的引用关闭值的部分,如果这有意义吗?