简体   繁体   中英

js method in Application.js not being called

I put the following method in my application.js file.

var formhandler = function() {
    var submit, isSubmit = false;
    submit = function(){
                // flop and return false once by the use of operator order.
    return isSubmit != (isSubmit = true);
    };
    return {
       submit: submit
       };
}(); // <-- use direct invcation to keep the internal variables "static"

It works fine if I write it directly in the header section of the form. However when I put it in the application.js file it is not being called or found.

How should I call functions that are in applcation.js.

Also I have the following in the header of the layout.

<%= javascript_include_tag :all, :cache => true, :recursive => true %>`enter code here`

I don`t fully understand your question,so I may be wrong, but as a remark:

here you always return false:

return isSubmit != (isSubmit = true);

I think it should be

return isSubmit != (isSubmit == true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM