这一段小代码在运行时报错:Uncaught TypeError: Cannot read property 'style' of null。
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>IFE ECMAScript</title>
</head>
<body>
<div id="fade-obj" style="width:300px;height:300px;background:rgb(0, 0, 0, 1)"></div>
<button id="fade-btn">淡出</button>
<script>
var button = document.getElementById("fade-btn");
var obj = document.getElementById("fade-boj");
var index = 0;
var transParent;
var intervalId;
function fadeOut() {
if (index === 1000) {
clearInterval(intervalId);
}
transParent = 1 - index / 1000;
console.log("sssssss")
console.log("style", obj.style);
obj.style.background = "rgb(0, 0, 0," + " " + transParent + ")";
index ++;
}
button.onclick = function() {
if(button.firstChild.nodeValue === "淡出") {
button.disabled = true;
intervalId = setInterval(fadeOut, 10);
}
}
</script>
</body>
</html>
跪求大神解答!谢谢
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>IFE ECMAScript</title>
</head>
<body>
<div id="fade-obj" style="width:300px;height:300px;background:rgb(0, 0, 0, 1)"></div>
<button id="fade-btn">淡出</button>
<script>
var button = document.getElementById("fade-btn");
var obj = document.getElementById("fade-boj");
var index = 0;
var transParent;
var intervalId;
function fadeOut() {
if (index === 1000) {
clearInterval(intervalId);
}
transParent = 1 - index / 1000;
console.log("sssssss")
console.log("style", obj.style);
obj.style.background = "rgb(0, 0, 0," + " " + transParent + ")";
index ++;
}
button.onclick = function() {
if(button.firstChild.nodeValue === "淡出") {
button.disabled = true;
intervalId = setInterval(fadeOut, 10);
}
}
</script>
</body>
</html>
跪求大神解答!谢谢
解决方案 »
- iframe获取焦点问题!!求大神!!
- 这句话在插件中有什么作用?var plugin = $.editable.types[settings.type].plugin || function ()
- 正则表达式 反取内容 从某个字符到某个字符
- 如何让submit按钮在onclick事件中return false的情况下不要提交?
- 问题不好描述,请大家看代码
- javascript 上传
- 关于【梅花雪】的树,请教!
- 移动图片的JAVASCRIPT,急求,谢谢
- 关于EXTJS的GridPanel
- 动态菜单怎么制作出来
- autocomplete控件和jqweui控件冲突的问题
- uploadifive 如何判断我这次的上传动作有没有附件上传
var obj = document.getElementById("fade-obj");二是有透明度的应该是rgba()
rgba(0, 0, 0, 1)
"rgba(0, 0, 0," + " " + transParent + ")";