开发者

load a form more than once using AJAX

开发者 https://www.devze.com 2023-01-26 16:01 出处:网络
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);

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

functio开发者_如何学Pythonn 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
}
0

精彩评论

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

关注公众号