I am working on a .net website with only a single Javascript (so far). Because I have been told Single JS get best performance etc. firstly, any suggestions on JS frameworks , any cutting-edged articles?
Secondly, I met some problems when I was trying to invoke JS function just for a child page. I tried something like :
1.I want to exe a function after a page_load (i.e. ispostback)
$("#div_ID").ready
2.exe a function after page postback (a dropdownlist post back in updatepanel)
pgRegMgr.add_beginRequest(BeginHandler)
function BeginHandler()
{$(".DDL_ClassName").change(function{.....});
}
Both not work. System won’t recognized the div or DDL.
I’m not able to set the function in $(document).ready or .add_beginReqest() in the ‘master’ JS, it will cause errors on other pages. Any suggestions? or do I have to move to multiple JS files?
Moreover, instead of writing inline javascript, I’m using
$(document).ready(function{textchange});
function textchange(function { $(".textbox_class").change(.....)});
It works in Chrome etc, but not for IE 7 (mb IE8 as well)
Can anyone help me?
Thanks a lot.
There’s a couple different ways you could do this.
Personally, I don’t see anything wrong with having a $(document.ready( on each page. Keep all your functions in a single .js file, but it is pretty handy (and still lightweight) to just have some simple init functions on each page. In that case you would do the same thing you had:
If you don’t want to have a $(document).ready() on your child page, you could use an if statement in your .js file. Use window.location.pathname to get the path to your file, and check this against what it should be for your child page. Your code might look like this :