结合2个jQuery函数 [英] Combine 2 jQuery functions

查看:62
本文介绍了结合2个jQuery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我已经尝试了一段时间在我的代码中组合了两个函数但是我无法让它正常工作。我希望有人可以帮助我...



1st



  function  formatTime(seconds){
var h = 数学 .floor(秒/ 3600 ),
m = 数学。 floor(秒/ 60 )% 60
s =秒% 60 ;
if (h< 10 )h = 0 + h;
if (m< 10 )m = 0 + m;
if (s< 10 )s = 0 + s;
return h + + m + + s;
}
var count = 5 ;
var counter = setInterval(timer, 1000 );

function timer(){
count--;
if (count< 0 return clearInterval(counter);
document .getElementById(' timer').innerHTML = formatTime(count);
}





2nd



 $( document )。ready( function (){
$( button)。click( function () {
$( 。verwijder)。eq( 0 )。remove();
});
});





第一段代码是计时器。当计时器为0或00:00:00时,我希望第二段代码发生,这将导致删除列表项。



下面你看到列表当计时器结束时将删除第一个项目



 <   div     id   =  vakjesdiv >  
< ul >
< span class =code-keyword>< li class = verwijder > < img class = aanbieding src < span class =code-keyword> = images / jack.png > < span id = timer > < / span > < / li > ;
< li class = verwijder > < img class = aanbieding src = images / kpn.png > < span id = timer2 > < / li >
< li class = verwijder > < img class = aanbieding src = images / mac.png > < / li >
< li class = verwijder > < img class = aanbieding src = images / pathe.png > < / li >
< / ul >
< < span class =code-leadattribute> / div >





我是一个现场演示这里 http://tinyurl.com/nam3hkr [ ^ ]



如果单击右上角的按钮,您将看到我想要创建的效果。

解决方案

document )。ready( function (){


button)。单击( function (){


。verwijder)。eq( 0 )。remove();
});
});





第一段代码是计时器。当计时器为0或00:00:00时,我希望第二段代码发生,这将导致删除列表项。



下面你看到列表当计时器结束时将删除第一个项目



 <   div     id   =  vakjesdiv >  
< ul >
< span class =code-keyword>< li class = verwijder > < img class = aanbieding src < span class =code-keyword> = images / jack.png > < span id = timer > < / span > < / li > ;
< li class = verwijder > < img class = aanbieding src = images / kpn.png > < span id = timer2 > < / li >
< li class = verwijder > < img class = aanbieding src = images / mac.png > < / li >
< li class = verwijder > < img class = aanbieding src = images / pathe.png > < / li >
< / ul >
< < span class =code-leadattribute> / div >





我是一个现场演示这里 http://tinyurl.com/nam3hkr [ ^ ]



如果单击右上角的按钮,您将看到我想要创建的效果。


Hello,

I've been tryin for a while to combine 2 functions in my code but I cant get it to work properly. I hope someone can help me out...

1st

function formatTime(seconds) {
    var h = Math.floor(seconds / 3600),
        m = Math.floor(seconds / 60) % 60,
        s = seconds % 60;
    if (h < 10) h = "0" + h;
    if (m < 10) m = "0" + m;
    if (s < 10) s = "0" + s;
    return h + ":" + m + ":" + s;
}
var count = 5;
var counter = setInterval(timer, 1000);

function timer() {
   count--;
   if (count < 0) return clearInterval(counter);
  document.getElementById('timer').innerHTML = formatTime(count);
}  



2nd

$(document).ready(function(){
$("button").click(function () {
    $(".verwijder").eq(0).remove();
});
});



The first piece of code is a timer. When the timer is 0 or 00:00:00 I want the 2nd piece of code to happend which will result in deleting a list item.

Below you see the list that will have its first item removed when the timer is over

<div id="vakjesdiv">
	<ul>
		<li class="verwijder"><img class="aanbieding" src="images/jack.png"> <span id="timer"></span></li>
		<li class="verwijder"><img class="aanbieding" src="images/kpn.png">	<span id="timer2"></li>
		<li class="verwijder"><img class="aanbieding" src="images/mac.png"></li>
		<li class="verwijder"><img class="aanbieding" src="images/pathe.png"></li>
	</ul>
</div>



I've a live demo here http://tinyurl.com/nam3hkr[^]

If you click on the button on the top right you will see the effect I want to create.

解决方案

(document).ready(function(){


("button").click(function () {


(".verwijder").eq(0).remove(); }); });



The first piece of code is a timer. When the timer is 0 or 00:00:00 I want the 2nd piece of code to happend which will result in deleting a list item.

Below you see the list that will have its first item removed when the timer is over

<div id="vakjesdiv">
	<ul>
		<li class="verwijder"><img class="aanbieding" src="images/jack.png"> <span id="timer"></span></li>
		<li class="verwijder"><img class="aanbieding" src="images/kpn.png">	<span id="timer2"></li>
		<li class="verwijder"><img class="aanbieding" src="images/mac.png"></li>
		<li class="verwijder"><img class="aanbieding" src="images/pathe.png"></li>
	</ul>
</div>



I've a live demo here http://tinyurl.com/nam3hkr[^]

If you click on the button on the top right you will see the effect I want to create.


这篇关于结合2个jQuery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆