gpt4 book ai didi

JavaScript 无法在 IE 上运行

转载 作者:行者123 更新时间:2023-12-02 19:33:04 24 4
gpt4 key购买 nike

我有以下代码,当将鼠标悬停在元素上时,将显示一个 div,并在鼠标移开时隐藏。这在除 IE 之外的每个浏览器上都可以正常工作,这是我的代码;

// JavaScript Document

var baseopacity=0
function showtext(thetext){
if (!document.getElementById)
return
textcontainerobj=document.getElementById("tabledescription")
browserdetect=textcontainerobj.filters? "ie" : typeof textcontainerobj.style.MozOpacity=="string"? "mozilla" : ""
instantset(baseopacity)
document.getElementById("tabledescription").innerHTML=thetext
highlighting=setInterval("gradualfade(textcontainerobj)",50)
}

function hidetext(){
cleartimer()
instantset(baseopacity)
}

function instantset(degree){
if (browserdetect=="mozilla")
textcontainerobj.style.MozOpacity=degree/100
else if (browserdetect=="ie")
textcontainerobj.filters.alpha.opacity=degree
else if (document.getElementById && baseopacity==0)
document.getElementById("tabledescription").innerHTML=""
}
function cleartimer(){
if (window.highlighting) clearInterval(highlighting)
}
function gradualfade(cur2){
if (browserdetect=="mozilla" && cur2.style.MozOpacity<1)
cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.2, 0.99)
else if (browserdetect=="ie" && cur2.filters.alpha.opacity<100)
cur2.filters.alpha.opacity+=20
else if (window.highlighting)
clearInterval(highlighting)
}
//<![CDATA[
$(window).load(function(){
$(".tiptext").mouseover(function() {
$(this).children(".description").show();
}).mouseout(function() {
$(this).children(".description").hide();
});
});//]]>

这是其中一个元素的 HTML(每个元素是一张图片);

<div id="one">
<div class="tiptext"><a href="http://mathremake.site40.net/"><img src="../images/web/1.png" height="180" width="300"/></a>
<div class="description"><font face="Arial, Helvetica, sans-serif"><u>Ascension Math Page</u></font><font size="2" face="Arial, Helvetica, sans-serif"><br>Ascension Collegiate's Mathematics department web page.</br></font></div>
</div>
</div>

以及同一元素的 CSS;

#one {
top: 200px;
position: absolute;
width: 300px;
position: absolute;
left: 50%;
margin-left: -500px;
}

感谢所有帮助,谢谢。 :)

最佳答案

IE $(window).load()有问题,你可以试试这个:

$(window).bind('load', function(){
...
});

或者:

$(document).ready(function() {
$(".tiptext").hover(function() {
$(this).find(".description").show();
}, function() {
$(this).find(".description").hide();
});
});

关于JavaScript 无法在 IE 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11279042/

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