Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.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 根据字符串数组中的元素数创建div可滚动元素_Javascript_Html_Jquery - Fatal编程技术网

Javascript 根据字符串数组中的元素数创建div可滚动元素

Javascript 根据字符串数组中的元素数创建div可滚动元素,javascript,html,jquery,Javascript,Html,Jquery,最重要的是,我对Javascript技术一无所知。我想根据字符串的数量在复选框数组中创建各种div,但在我的代码之后,每次只显示一个div。。。我必须通过jquery对话框来显示它 我的JSP <div style="overflow: scroll;" id="listCurrentContact"></div> My listContact.js varPopup = $('#dialogMultiplesDeleteCo

最重要的是,我对Javascript技术一无所知。我想根据字符串的数量在复选框数组中创建各种div,但在我的代码之后,每次只显示一个div。。。我必须通过jquery对话框来显示它

我的JSP

<div style="overflow: scroll;" id="listCurrentContact"></div>

My listContact.js

varPopup = $('#dialogMultiplesDeleteConfirmation').dialog({
        resizable : false,
        modal : true,
        autoOpen : false,
        width : 500,
        open: function(){
            var SuppressCheckboxItems = [];
            // I put into an array the different value of checked checkboxes
            $("input:checkbox[id=suppressCheckbox]:checked").each(function() {
                SuppressCheckboxItems.push($(this).val());
            });
            var z = document.createElement('div');
            // I suppress the ',' between each element
            var test = SuppressCheckboxItems.toString();
            var tab = test.split(",");
            for(var i = 0; i < tab.length; i++){
                    z.innerHTML = tab[i];
                    $('#listCurrentContact').html(z);
            }
varPopup=$('#dialogMultiplesDeleteConfirmation')。dialog({
可调整大小:false,
莫代尔:是的,
自动打开:错误,
宽度:500,
打开:函数(){
var SuppressCheckboxItems=[];
//我将不同的复选框值放入一个数组中
$(“输入:复选框[id=suppressCheckbox]:选中”)。每个(函数(){
SuppressCheckboxItems.push($(this.val());
});
var z=document.createElement('div');
//我抑制每个元素之间的“,”
var test=SuppressCheckboxItems.toString();
var tab=测试分割(“,”);
对于(变量i=0;i
您应该使用$('#listCurrentContact').append(z);

您应该使用$('#listCurrentContact').append(z);

在将复选框连接到
listCurrentContact
时,您是否尝试过使用
.append
而不是
.html

您可以参考此文档:查看.html()将以前的内容替换为新内容,而您在此处尝试实现的是将整个值数组追加到div。请查看
.append()
在该链接中的工作方式:。在编写.append()时,只需简单概述一下在任何元素上,它都不会用新内容替换以前的内容,而是在以前的内容之后附加/连接新内容。

在将复选框连接到
#listCurrentContact
时,是否尝试使用
.append
而不是
.html

您可以参考此文档:查看.html()将以前的内容替换为新内容,而您在此处尝试实现的是将整个值数组追加到div。请查看
.append()
在该链接中的工作方式:。在编写.append()时,只需简单概述一下在任何元素上,它都不会用新内容替换以前的内容,而是在以前的内容之后附加/连接新内容。

多亏了Salonimshra,我找到了好答案。它只需要将.html()更改为.append()但是如果客户退出jquery对话框并重试div中以前的元素,那么您需要在使用函数removeChild()重新启动函数之前清理所有元素!谢谢

open : function() {
            var SuppressCheckboxItems = [];
            const currentDiv = document.getElementById('listCurrentContact');
            while (currentDiv.firstChild) {
                currentDiv.removeChild(currentDiv.lastChild);
            }
            $("input:checkbox[id=suppressCheckbox]:checked").each(function() {
                var z = document.createElement('div');
                z.innerHTML = $(this).attr("name");
                $("#listCurrentContact").append(z);
            });

感谢Salonimshra,我找到了一个好答案。它只需要将.html()更改为.append(),但是如果客户只是退出jquery对话框并重试之前留在div中的元素,那么在使用函数removeChild()重新启动函数之前,您需要清理每个元素!谢谢大家

open : function() {
            var SuppressCheckboxItems = [];
            const currentDiv = document.getElementById('listCurrentContact');
            while (currentDiv.firstChild) {
                currentDiv.removeChild(currentDiv.lastChild);
            }
            $("input:checkbox[id=suppressCheckbox]:checked").each(function() {
                var z = document.createElement('div');
                z.innerHTML = $(this).attr("name");
                $("#listCurrentContact").append(z);
            });

您可能必须使用append
$(“#listCurrentContact”)。append(z)
查看文档您可能必须使用append
$(“#listCurrentContact”)。append(z)
查看文档