开发者

.slideDown and .click(function() {$("#results").slideUp("slow");}); Clash

I have:

table2.assemble = function () {
  $("#results").slideDown("slow");
  $("#fullbody").click(function() {
    $("#results").slideUp("slow");
  });
}

embedded in a function that is called with an onclick of a search button that is in #fullbody

window.addEventListener('load', function () {
  document.getElementById('sssearch').addEventListener('click', table2.assemble, false)
}, false);

The search results slide down fine...but slide up again instantly when I have not clicked a second time.

The div is:

开发者_C百科<div id="results" style="display: none;">
</div>


In the below code you are attaching a click handler to fullbody element inside a function which is called onclick of sssearch element. Every time you click sssearch the click handler is going to be attached. So there will be multiple click event handlers.

table2.assemble = function () {
  $("#results").slideDown("slow");
  $("#fullbody").click(function() {$("#results").slideUp("slow");});
}

Take it outside the function. I think the issue is here only.

$("#fullbody").click(function() {$("#results").slideUp("slow");});

table2.assemble = function () {
  $("#results").slideDown("slow");
}

Also to execute anything on page load you can use jQuery's $(document).ready() or $().

$(function(){
   //Do your stuff here
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜