2012-09-14 133 views
0

以下是我的JavaScript中,我一直在试图显示某些股利,执行功能后,div应该隐藏自己,但我有这个问题,在相同的功能都不工作像先显示一段时间后隐藏该div,但是当我将显示和隐藏事件分开时,它工作正常。请让我知道我可以修改下面的代码,使处理后的结果应该隐藏该divjquery隐藏不被触发

function jq(input) 
    { 


    if (input == 'abc') 
    { 
    $("#show").show(1000); 

     document.getElementById('sele').options.length = 0; 

    $('#sele').append('<option value="test">Testing</option>').updateSelect(); 

    $("#show").hide(1000); 

    } 
} 

<div id="show" > <img src="ajax-loader.gif" width="16" height="16" /> </div> 

回答

1
$("#show").show(1000, function() { 

    $('#sele').empty(); // instead of: document.getElementById('sele').options.length = 0; 

    $('#sele').append('<option value="test">Testing</option>').updateSelect(); 

    // make a delay using setTimeout() 
    setTimeout(function() { 

     $("#show").hide(1000); 

    }, 500); 

}); 

完整的代码

function jq(input) { 
    if (input == 'abc') { 
     $("#show").show(1000, function() { 
      $('#sele').empty(); 
      $('#sele').append('<option value="test">Testing</option>').updateSelect(); 
      setTimeout(function() { 
       $("#show").hide(1000); 
      }, 500); 
     }); 
    } 
} 
+0

谢谢,但隐藏的问题仍然存在... 。 –

+0

@softgenic您是否尝试过我的上次更新代码?如果之后有任何问题,然后澄清......更好的是在http://jsfiddle.net小提琴 – thecodeparadox

0

我觉得你越来越下一行的错误(检查控制台):

document.getElementById('sele').options.length = 0; 

length是只读的,那不是清空select的方法。由于您使用jQuery,你可以做这样的事情,而不是:

$('#sele').empty();