Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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 添加时动态数据消失_Javascript_Jquery_Forms_Dynamic_Bootstrap Modal - Fatal编程技术网

Javascript 添加时动态数据消失

Javascript 添加时动态数据消失,javascript,jquery,forms,dynamic,bootstrap-modal,Javascript,Jquery,Forms,Dynamic,Bootstrap Modal,我有一个表单可以添加外部用户,其中两个字段在默认情况下不是必需的。但是,只有在填写其中一个字段时,它们才成为必填项。单击apply按钮后,我表单的内容将用于生成一个动态div,该div将附加到“div.container”中。然而,它一加上就消失了 原因可能是什么 代码如下: var currentPageNo=0;//跟踪当前显示的页面 //选择userList的后代按钮 $('#userList.prev btn')。单击(函数(){ 用户列表(当前第10页); }); $('#userL

我有一个表单可以添加外部用户,其中两个字段在默认情况下不是必需的。但是,只有在填写其中一个字段时,它们才成为必填项。单击apply按钮后,我表单的内容将用于生成一个动态div,该div将附加到“div.container”中。然而,它一加上就消失了

原因可能是什么

代码如下:

var currentPageNo=0;//跟踪当前显示的页面
//选择userList的后代按钮
$('#userList.prev btn')。单击(函数(){
用户列表(当前第10页);
});
$('#userList.next btn')。单击(函数(){
用户列表(当前页码+10);
});
$('#adminList.prev btn')。单击(函数(){
管理员列表(当前第10页);
});
$('#adminList.next btn')。单击(函数(){
管理员列表(当前页码+10);
});
函数用户列表(页码){
var resType=“userList”;
createTable(重新键入,页码);
}
功能管理员列表(页码){
var resType=“adminList”;
createTable(重新键入,页码);
}
函数createTable(重新类型,页码){
//更新全局变量
currentPageNo=pageNo;
//设置正确“prev”按钮的可见性:
$(“#”+resType+”.prev btn')。切换(页码>0);
//多询问一条记录,以确定此页面后是否有更多记录:
$.getJSON(“https://api.randomuser.me/?results=11&resType=“+resType+”&pageIndex=“+pageNo,函数(数据){
var$table=$('#'+resType+'table');
$('tr:has(td)',$table.empty();
//检查是否有我们不显示的额外记录,
//但确定存在下一页
$(“#”+resType+”.next btn').toggle(data.results.length>10);
//切片结果,因此不包括第11条记录:
data.results.slice(0,10).forEach(函数(record,i){//为记录编号添加第二个参数
var json=json.stringify(记录);
$table.append(
$('')。追加(
$('')。追加(
$('').attr('类型','复选框')
.addClass('selectRow')
.val(json),
(i+1+pageNo)//显示行号
),
$('')。追加(
$('').attr('href',record.picture.缩略图)
.addClass('imgurl')
.attr('target','u blank')
.text(记录.name.first)
),
$('').append(record.dob)
)
);
});
//显示上一个和/或按钮
}).失败(功能(错误){
log(“*********AJAX错误:+错误);
});            
}
var savedData=[];//将对象设置为数组,以便具有顺序。
函数saveData(){
var错误=[];
//将所选内容添加到地图
$('input.selectRow:checked')。每个(函数(计数){
//获取存储为复选框值的JSON
var obj=JSON.parse($(this.val());
//查看是否已收集此URL(使用Set很容易)
if(savedData.find(record=>record.picture.thumbnail===obj.picture.thumbnail)){
错误。推送(对象名称。第一);
}否则{
//附加它
保存数据推送(obj);
}
});
刷新显示();
if(errors.length){
警报('已选择下列项:\n'+错误。加入('\n'));
}
}
函数刷新显示(){
$('.container').html('');
savedData.forEach(函数(obj){
//重置容器,并附加收集的数据(使用jQuery进行附加)
$('.container')。追加(
$('').addClass('parent').append(
$('').addClass('dataLabel').text('Name:'),
obj.name.first+“”+obj.name.last,
$(“
”),//名称和图片之间的换行符 $(''), $('').addClass('dataLabel').text('Date of birth:'), obj.dob,$(“
”), $('').addClass('dataLabel').text('Address:'),$('
'), obj.location.street,$(“
”), obj.location.city+“”+obj.location.postcode,$(“
”), obj.location.state,$(“
”), $('').addClass('removeMe').text('Delete'), $('').addClass('top-btn').text('Swap with top'), $('').addClass('down-btn').text('Swap with down') ) ); }) //清除复选框: $('.selectRow').prop('checked',false); 把手通风孔(); } 函数logSavedData(){ //转换为JSON并记录到控制台。您可以将其发布 //指向某个URL,或将其保存到localStorage。 log(JSON.stringify(savedData,null,2)); } 函数getIndex(elem){ 返回$(elem).parent('.parent').index(); } $(文档).on('click','removeMe',函数(){ //从保存的数据中删除此项 savedData.splice(getIndex(this),1); //重新发现 刷新显示(); }); /*交换结果列表中显示的项目*/ $(文档).on('click',“.down btn”,函数(){ var指数=getIndex(本); //内存交换 拼接(索引,2,savedData[index+1],savedData[index]); //重新发现 刷新显示(); }); $(文档).on('单击',“.top btn”,函数()){ var指数=getIndex(本); //内存交换 savedData.splice(索引-1,2,savedData[index],savedData[index-1]); //重新发现 刷新显示(); }); /*分别为结果列表中的第一篇文章和最后一篇文章禁用自上而下按钮(&D)*/ 函数handleEvents(){ $(“.top btn,.down btn”).prop(“disabled”,false).show(); $(“.parent:first”).find(“.top btn”).prop(“disabled”,true).hide(); $(“.parent:last”).find(“.down btn”).prop(“dis
return true;
return false;