开发者

jQuery + Ruby on Rails Repeating Code

开发者 https://www.devze.com 2023-01-23 12:57 出处:网络
I have the following jquery method: (function($){ $(document).ready(fu开发者_如何转开发nction() {

I have the following jquery method:

(function($){
  $(document).ready(fu开发者_如何转开发nction() {
      $("select[name='publication_type[category]'] ").change(function (){
          alert("It works");

       });

    });
})(jQuery);

It operates on the following ruby code:

select("publication_type", "category", @filters.selections.collect(&:name), :id =>"publication_type" ) 

Each time I choose a different option from the drop down box, the alert method fires twice. The intention is that it should only fire once. Any ideas?

Thanks in advance...


I don't know about the double alert, but don't use the "change" event. IE does not fire the change event on a select element until it loses focus, not when the value changes.

edit: same goes for radio buttons and checkboxes.


I discovered the problem...I had added the javascript file in two places...one in the layout template and another in the view that was being rendered.

0

精彩评论

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