Javascript 如何提醒每一个事件?
每次z指数等于2时,我都需要向用户发送警报。不幸的是,它只发生在加载,或准备就绪…无论什么 这是htmlJavascript 如何提醒每一个事件?,javascript,Javascript,每次z指数等于2时,我都需要向用户发送警报。不幸的是,它只发生在加载,或准备就绪…无论什么 这是html <div id='slides'> <img class='sliderImg' src='img.jpg'> <img class='sliderImg' src='img.jpg'> <img class='sliderImg' src='img.jpg'> </div> 你有两个选择: 1) 运行计时器并使
<div id='slides'>
<img class='sliderImg' src='img.jpg'>
<img class='sliderImg' src='img.jpg'>
<img class='sliderImg' src='img.jpg'>
</div>
你有两个选择:
1) 运行计时器并使用setInterval或setTimeout定期调用函数
2) ,然后运行函数。您可以在t时间后使用函数检查z索引,如下所示:
window.setInterval(function(){
var theImage=$('.sliderImg')[0];
if(theImage.style.zIndex==2){
alert(theImage.style.zIndex);
}
},10000);
它将每10秒调用一次。jQuery风格:
document.ready = function(){
checkZIndexOfImage(zIndex);
window.setInterval(checkZIndexOfImage, 10000);
}
function checkZIndexOfImage(zIndex) {
var theImage=$('.sliderImg').first(); //or $('.sliderImg').eq(0)
var tempzIndex = theImage.style('z-index');
tempzIndex = parseIng(zIndex);
if (isNaN(tempzIndex)) { //Let's check z-index is number
tempzIndex = 0;
}
if(tempIndex === zIndex){
alert(tempzIndex );
}
}
你希望它什么时候发生?看看这个主题:这可能会对你有所帮助
document.ready = function(){
checkZIndexOfImage(zIndex);
window.setInterval(checkZIndexOfImage, 10000);
}
function checkZIndexOfImage(zIndex) {
var theImage=$('.sliderImg').first(); //or $('.sliderImg').eq(0)
var tempzIndex = theImage.style('z-index');
tempzIndex = parseIng(zIndex);
if (isNaN(tempzIndex)) { //Let's check z-index is number
tempzIndex = 0;
}
if(tempIndex === zIndex){
alert(tempzIndex );
}
}