0

如何使用 Javascript 或 html 为我的站点创建跨浏览器友好的文本轮播?我一直在努力使用下面的代码,因为它只适用于 Firefox,但它在 IE 上失败。有没有办法让它在两者上都起作用?

<h4>Carousel-Text-Below </h4>

<html>
<head>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'    
type='text/javascript'></script>
<script type='text/javascript'>
$(document).ready(function(){
function setRandomWord(){
    var phrases =new Array("1-Blah Text","2-Blah Text","3-Blah Text");  
    $("#test").text(phrases[Math.floor(Math.random()*phrases.length)]);
}
setInterval(setRandomWord,3000);
});
</script>
</head>
<body> 
<p style="border:1px dashed gray; background-color:white; padding: 10px">
<span id='test'>Blah Text-Text-Text</p>
</span> Guaranteed Service or...Text---Text</strong></p> 
</body> 
</html>
4

2 回答 2

1

我认为这是因为您没有设置文档类型。在这里尝试过,它可以<!DOCTYPE html><html>标签前面使用。

于 2013-01-13T22:11:36.577 回答
1

也许 IE 对您的无效 HTML 感到困惑?请注意,您在关闭它<p>之前关闭<span>它。然后你也有无与伦比的</strong></p>在最后。我相信你的意思是:

<p style="border:1px dashed gray; background-color:white; padding: 10px">
    <span id='test'>Blah Text-Text-Text</span>
    <strong>Guaranteed Service or...Text---Text</strong>
</p>

http://jsfiddle.net/xrS3t/

或者可能

<p style="border:1px dashed gray; background-color:white; padding: 10px">
    <span id='test'>Blah Text-Text-Text</span>
</p>
<p>
    <strong>Guaranteed Service or...Text---Text</strong>
</p>

http://jsfiddle.net/6nFVK/

我现在没有IE来测试,你可以试试上面的jsfiddle链接吗?

于 2013-01-13T22:20:58.573 回答