Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用AJAX多次加载表单_Javascript_Html_Ajax - Fatal编程技术网

Javascript 使用AJAX多次加载表单

Javascript 使用AJAX多次加载表单,javascript,html,ajax,Javascript,Html,Ajax,我只是想使用循环多次加载表单/div。试过这个- 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.getE

我只是想使用循环多次加载表单/div。试过这个-

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;
    }

对于(i=1;i您需要使用其他一些方法来访问您的元素,因为您只能按ID引用单个元素。一个选项是按类引用它们,或者如果是我的选择,请使用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
}
var myHTML=“…随便什么”;//这是我们在某处构建的HTML
var myDIV=$('');//这里我们在jQuery中创建一个DOM对象
$(myDiv).addClass('myClass');//这里我们添加了一个类,以便以后可以找到它们
$(myDiv).append(myHTML);//在这里,我们插入前面构建并在顶部引用的HTML

(x=1;席)在你的代码段中没有看到很多ajax相关的代码。你确定你在这里没有混合一些概念吗?我只需要使用循环加载一次HTML div。我在这个JavaScript平台上是新的。所以,任何例子都会有帮助。你说的“加载”是什么意思??当你说AJAX时,听起来好像html表单是单独下载到主页的(即在另一个文件中),但从你的示例来看,你似乎只是想“复制”一个已经在页面上的表单。我创建了一个div并将其隐藏。所以我想在一个循环下加载它几次。迭代的次数将是动态的。这就是我到目前为止想要做的。实际上我对jQuery没有太多的了解。有人能提供任何javascript示例吗?下载:code.jQuery.com/jQuery-1.4.4.js。阅读:docs.jQuery.com/教程:开始使用jQuery。尝试一下,它会让你的生活更轻松,尽管这是另一件需要学习的事情。