开发者

Simple jQuery toggle() and return false inside click()

开发者 https://www.devze.com 2022-12-27 05:13 出处:网络
I\'m mostly a djangonaut and phper, but I\'m getting javascript development. I\'ve been looking at this very simple block for a feedback widget on a page. The code is pretty self-explanatory.

I'm mostly a djangonaut and phper, but I'm getting javascript development.

I've been looking at this very simple block for a feedback widget on a page. The code is pretty self-explanatory.

<a id="feedback-widget-toggle" href="[feedback_url]">Feedback</a>
<div id="feedback-widget">
  <form method="POST" action="[form_url]">
    ...
  </form>
</div>

<script type="text/javascr开发者_如何学Goipt">
  $(document).ready(function() {
    $("#feedback-widget-toggle").click(function() {
      $("#feedback-widget").toggle("slide", {}, 500);
      return false;
    });
  });
</script>

It's really simple. So simple that I feel pretty dumb for this one.

The jQuery is just supposed to disable the link and slide out the feedback-widget div. That's it. I'm new to jQuery, so it's probably some very simple syntax error that I'm not sure how to debug well enough.

Thanks.


<script type="text/javascript">
  $(document).ready(function() {
    $("#feedback-widget-toggle").click(function() {
      $("#feedback-widget").slideToggle(500);
      return false;
    });
  });
</script>


Have you tried:

$("#feedback-widget").slideToggle(500);


Your link should already get disabled with 'return false'. Alternate call here is to give the closure function a parameter (e.g. 'event') and call event.preventDefault();

as for the slide out use .slideToggle(500);

0

精彩评论

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