Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery在mouseenter div上开始倒计时,然后在“上显示图像”;0“;_Jquery - Fatal编程技术网

Jquery在mouseenter div上开始倒计时,然后在“上显示图像”;0“;

Jquery在mouseenter div上开始倒计时,然后在“上显示图像”;0“;,jquery,Jquery,我对jquery了解不多,但我知道这是实现这种效果的唯一方法 当前代码: JQUERY: <script type="text/javascript"> var settimmer = 0; $(function(){ window.setInterval(function() { var timeCounter = $("b[id=show-time]").html(); var

我对jquery了解不多,但我知道这是实现这种效果的唯一方法

当前代码:

JQUERY:

<script type="text/javascript">
    var settimmer = 0;
    $(function(){
            window.setInterval(function() {
                var timeCounter = $("b[id=show-time]").html();
                var updateTime = eval(timeCounter)- eval(1);
                $("b[id=show-time]").html(updateTime);

                if(updateTime <= 0){
                    $("#timer").load("images/logo.png");
                }
            }, 1000);

    });
</script>

var settimmer=0;
$(函数(){
setInterval(函数(){
var timeCounter=$(“b[id=show time]”)html();
var updateTime=eval(计时器)-eval(1);
$(“b[id=show time]”)html(updateTime);

如果(更新时间首先有几个点

使用id时,您不需要像
b[id=show time]
这样的选择器,只需使用
#show time

其次,您应该始终避免
eval
,另外,您真正想要的是
parseInt
——当然,您永远不需要计算一个文字数字

var updateTime = parseInt(timeCounter,10) - 1;
现在,为了回答您的问题,您需要在
mouseover
的事件处理程序中执行函数。此外,您应该只启动计时器一次,并记住在计时器达到0时停止计时器

$(function(){
    var timerId = 0;
    $('#timerwrap').mouseover(function(){
        if(timerId == 0){
            timerId = window.setInterval(function() {
                var timeCounter = $("#show-time").html();
                var updateTime = parseInt(timeCounter,10) - 1;
                $("#show-time").html(updateTime);

                if(updateTime <= 0){
                    clearTimeout(timerId);
                    $("#timer").css({background:"url(images/logo.png)"});
                }
            }, 1000);
        }
    });
 });
$(函数(){
var-timerId=0;
$('#timerwrap').mouseover(函数(){
if(timerId==0){
timerId=window.setInterval(函数(){
var timeCounter=$(“#显示时间”).html();
var updateTime=parseInt(timeCounter,10)-1;
$(“#显示时间”).html(更新时间);

如果(更新时间这正是我想要的!非常感谢您的帮助和解释。还有一个小问题:当我更改“显示时间到”容器4时,它不工作。我做错了什么?我的意思是,如果我想通过鼠标在不包含计时器的单独div上启动计时器?再次感谢。不用担心。我找到了。我感觉到了像这样的n00b。谢谢!
$(function(){
    var timerId = 0;
    $('#timerwrap').mouseover(function(){
        if(timerId == 0){
            timerId = window.setInterval(function() {
                var timeCounter = $("#show-time").html();
                var updateTime = parseInt(timeCounter,10) - 1;
                $("#show-time").html(updateTime);

                if(updateTime <= 0){
                    clearTimeout(timerId);
                    $("#timer").css({background:"url(images/logo.png)"});
                }
            }, 1000);
        }
    });
 });