简体   繁体   English

如何使用javascript或html为我的网站制作一个跨浏览器友好的文本轮播?

[英]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.

相关问题 如何将Javascript注入网站,然后确保它与跨浏览器兼容? - How can I inject Javascript into a site, then make sure it's cross-browser compatible? 如何使用 HTML5、CSS 和 Javascript 制作图像轮播? - How can I make an image carousel using HTML5, CSS and Javascript? 如何使用引导程序 4 使 Javascript 用于轮播? - How can i make the Javascript work for a Carousel by using bootstrap 4? HTML中包含的JavaScript库可以使用cookie会话向我的网站发出请求吗? - Can a JavaScript library included in my HTML make a request to my site using my cookie session? 如何使用Javascript创建简单的fadeToggle导航/站点? - How can I make a simple fadeToggle nav/site using Javascript? 使用javascript history.back()在Safari中失败..如何让它跨浏览器? - Using javascript history.back() fails in Safari .. how do I make it cross-browser? Javascript OnClick跨浏览器友好? - Javascript OnClick cross-browser friendly? 如何使用JavaScript以跨浏览器方式将DOM序列化为XML文本? - How do I serialize a DOM to XML text, using JavaScript, in a cross browser way? 如何使我的网站跨浏览器兼容? - How do I make my website cross-browser compatible? 验证用户名和密码时,如何防止使用JavaScript SAPUI5进行跨站点脚本编写? - How can I prevent Cross-Site-Scripting using JavaScript SAPUI5 When validating user and password?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM