I have a series of divs in a pattern of header / body, where one click on the title will show the body in question
It happens with everything. Initially click on page preparation ...
Instead of doing so (which works fine, but pain):
$ ('# show_fold_ping') . Click (function () {ShowArea ('# fold_ping')}); $ ('# Show_fold_http') Click (function () {ShowArea ('# fold_http')}); $ ('# Show_fold_smtp') Click (function () {ShowArea ('# fold_smtp')}); $ ('# Show_fold_pop3'). Click (function () {ShowArea ('# fold_pop3')}); ...
I am trying to do this:
var area = ['ping', 'http', 'smtp', ' Pop3 ']; For (areas i var) {region = '#show_fold_' regions]; $ (Area). Click (function () {warning (region); / * showere (area); * /}); }
The problem I am facing is that all of them are being started the last time IE: If POP3 is last, then click #show_fold_ [Anyone ] # Show_fold_pop3.
It seems that it should be really simple, am I clarifying something, or is there a problem with passing a string in jQuery that I do not know?
Edit:
Hey, all of them are great I've read a little bit on closor and self-invoking functions, and (merciful) get it Have done
So far, I have this, but the click does not seem to be binding properly, the area will alert with the correct value, but there will be no click bind. Am I still presenting problems with the area, or am I completely away from the mark?
$ (function () {fields = ['ping', 'http', 'smtp', 'pop3', 'iap', 'ftp', 'dns', 'tpp' , 'Database', 'seo']; (var i = 0; i & lt; regions lamps; i ++) {(function) {alert (area); $ ("# show_fold _" + Field). (Function () {warning ('x');});}) (field [i]);}});
Yes, I have gone too much in this problem. Regions
is a global variable because it does not have var
before that, besides, do not use ... to build.
But you can still run into a similar problem. God knows how many scripts I've debited because of a similar bug, making the following guarantees to give a reasonable guarantee:
var areas = ['ping', 'http', 'smtp' 'Pop3']; For (var i = 0; i & lt; region; long; i ++) {(function (area) {$ (area). Click (function () {warning (region); / * Showere (region) ; * /});}) (Field [i]); }
Comments
Post a Comment