简体   繁体   中英

load a form more than once using AJAX

I simply want to load a form/div more than once using a loop. Tried this -

for (i=1; i<=4; i++) {
            //document.write(i);
            showObj('poidiv','block');
        }
// here poidiv is the name of a html div defined earlier

function showObj(objname,visibility){
        document.getElementById(objname).style.display= visibility;
    }

but not working.

Is it actually possible to load the same div/form more than once using javascript?

you will need to use some other method for accessing your element as you can only reference single elements by ID. an option would be to reference them by class, or were it my choice, use jQuery and it's built in selector..

var myHTML='...whatever';  // this is the HTML we built somewhere
var myDIV=$('<div/>');     // here we create a DOM object in jQuery
$(myDiv).addClass('myClass'); // here we add a class so we can find them later
$(myDiv).append(myHTML);  // here we insert the HTML we built earlier and referenced up top

for(x=1;x<=4,x++){  // here we loop
   $('#someDistinceElementOnPage').append($(myDiv));  // here we append that HTML with it's surrounding DIV to some element on the page
}

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