[英]JavaScript function not work onload
I have write a JavaScript code to perform a slide show but it's not working onload when i assign it to a <a>
it works but not work onload 我已经编写了JavaScript代码来执行幻灯片放映,但是当我将其分配给<a>
时却无法正常工作,但无法正常工作
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Slide Show</title>
<meta name="author" content="Jenz" />
<!-- Date: 2014-07-18 -->
<script>
var slideImg;
var picNo = 0;
window.onload = function() {
slideImg = document.getElementById('slideShowImage');
images = new Array();
images[0] = new Image();
images[0].src = "Images/image1.jpg";
images[1] = new Image();
images[1].src = "Images/image2.jpg";
images[2] = new Image();
images[2].src = "Images/image3.jpg";
};
function slide() {
slideImg.src = images[picNo].src;
if (picNo < 2) {
picNo++;
} else {
picNo = 0;
}
timer = setTimeout(slide, 1000);
};
</script>
</head>
<body>
<div style="margin-left: auto; margin-right: auto; width: 900px">
<div id="slideShowAndNav" style="margin: auto; width: 700px;">
<img id="slideShowImage" name="slideshow" src="Images/image1.jpg" style="border-radius: 0px 0px 0px 250px; position: absolute; top: -50; left: -50; z-index: 1;" border="1px" />
<a style="display: block; height: 40px; width: 40px; background-color: red; border-radius: 20px; text-align: center; position: absolute; z-index: 2; margin-top: 130px;" href="">Home</a>
</div>
</div>
</body>
</html>
Please look at the code and tell me what should i do and other thing i have a navigation which code is 请查看代码,并告诉我该怎么办,而我在导航中有哪些代码是
<a style="display: block; height: 40px; width: 40px; background-color: red; border-radius: 20px; text-align: center; position: absolute; z-index: 2; margin-top: 130px;" href="">Home</a>
i want this <a>
in a circle as i did with border-radius and now i want it's Text in the center like Home in the middle of the circle help me also with this 我要像在边框半径上一样在一个圆圈中<a>
,现在我希望它位于中间的文本(如Home)在圆圈中间,也可以帮助我
For this, use:- 为此,请使用:i want this in a circle as i did with border-radius and now i want it's Text in the center like Home in the middle of the circle help me also with this 我希望像在边框半径中那样将其圈成一个圆圈,现在我希望它位于中间的文本(如“居中”中的“家”)也可以帮助我
style="border-radius:100px; text-align:center;"
The " xmlns " attribute is invalid in HTML 4.01. “ xmlns ”属性在HTML 4.01中无效。 (You can change your doctype.) (您可以更改文档类型。)
Also, it is more common practice to create your function. 另外,创建函数是更常见的做法。
function blaah(blaah){
blaah
}
And then add an onload event handler, either with an event listener , or add this code to your body tag, 然后添加一个带有事件监听器的onload事件处理程序,或将此代码添加到您的body标签中,
<body onload="blaah('blaah')">
or, you could add this code in your script tags, but outside of the function. 或者,您可以将此代码添加到脚本标签中,但在函数之外。
blaah("blaah");
Call slide function. 调用幻灯片功能。
window.onload = function() {
slideImg = document.getElementById('slideShowImage');
images = new Array();
images[0] = new Image();
images[0].src = "Images/image1.jpg";
images[1] = new Image();
images[1].src = "Images/image2.jpg";
images[2] = new Image();
images[2].src = "Images/image3.jpg";
slide();
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.