简体   繁体   English

使用AJAX多次加载表单

[英]load a form more than once using AJAX

I simply want to load a form/div more than once using a loop. 我只是想使用循环多次加载一个form / div。 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? 实际上是否可以使用javascript多次加载同一div / form?

you will need to use some other method for accessing your element as you can only reference single elements by ID. 您将需要使用其他方法来访问元素,因为您只能按ID引用单个元素。 an option would be to reference them by class, or were it my choice, use jQuery and it's built in selector.. 一个选择是按类引用它们,或者是我选择使用jQuery,它是内置的选择器。

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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