0

I'm trying to show a loading gif after to press some key on a form.

I have this code. When I press a key the image is shown, but then if you did not press anything, still displays..... I want something that when I press a key the imagen is display and when I stop to press keys the imagen stop to showing

<html>
<head>
    <script type="text/javascript" src="jquery-1.8.2.min.js"></script>  
</head>
<body>
    Enter your name: <input type="text" id="fname" onkeyup="displayResult()">
    <img src="ajaxload.gif" id="load" style="display: none">
    <script>
        function displayResult()
        {
            $("#load").show();
        }
    </script>
</body>

Thanks in advance

4

1 回答 1

1

这应该有效:

$('#fname').keydown(function(){$("#load").show();});
$('#fname').keyup(function(){$("#load").hide();});

尽量避免内联事件处理程序。

是一个做你想做的小提琴。我没有你的图片,所以我使用了一个 div。

于 2012-10-14T18:10:08.153 回答