I have a series of images laid on top of one another. I intend to bring one to the front and animate its opacity. I am using the following code:
document.getElementById('newFrame').style.zIndex="10";
Having set the id in the following way:
var newFrame = "p" + rand;
(rand is a random number, and the image id's are p1, p2 etc)
But I'm getting the error "Cannot read property 'style' of 'null'"
and despite multiple changes I can not get this to work - please help.
newFrame是一个对象,因此您需要像一个对象一样引用它。您需要执行以下操作:
document.getElementById(newFrame).style.zIndex="10";
Very simply, you aren't using the variable you've set, you're using a string instead.
Your code is looking for an element with the ID of 'newFrame' rather than an ID 'p'+rand()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.