[英]How can I make a text carousel for my site cross browser friendly by using javascript or html?
How can I make a text carousel for my site cross browser friendly by using Javascript or html? 如何使用Javascript或html为我的网站提供跨浏览器友好的文本轮播? I have struggled with the code below because it will only work with Firefox but it fails on IE. 我一直在努力使用下面的代码,因为它只适用于Firefox,但它在IE上失败了。 Is there a way I can make it work on both? 有没有办法可以让它兼顾两者?
<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>
I presume it is because you don't have a doctype set. 我认为这是因为你没有设置doctype。 Tried it here, and it works with <!DOCTYPE html>
in front of the <html>
tag. 在这里尝试过,它在<html>
标签前面与<!DOCTYPE html>
一起使用。
Maybe IE is getting confused by your invalid HTML? 也许IE被你的无效HTML搞糊涂了? Note that you're closing the <p>
before closing the <span>
inside it. 请注意,您要关闭<p>
在关闭前<span>
里面。 Then you also have unmatched </strong>
and </p>
at the end. 那么你最后也有无与伦比的</strong>
和</p>
。 I believe you meant this: 我相信你的意思是:
<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/ http://jsfiddle.net/xrS3t/
Or maybe 或者可能
<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/ http://jsfiddle.net/6nFVK/
I don't have IE to test right now, could you try the above jsfiddle links? 我现在没有IE测试,你能试试上面的jsfiddle链接吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.