最近搜索

如何快速 遍历 table 遍历 dom节点 遍历 div的方法。

浏览:411
管理员 2022-10-15 23:41



var task_json = "[";
var trList = $("table#taskList tbody tr");
//console.log("trList:"+trList.size());
var order  = 0;//重新定义排序号,防止row不是从第0行开始,如果从1行开始后面展示有问题。 order代替row
for(var i=0;i<trList.size();i++){
   var row = trList.eq(i).attr("row");
   var user_ids = trList.eq(row).attr("user_ids");
   var user_text = trList.eq(row).attr("user_text");
   var project_text = trList.eq(row).attr("project_text");//
   var sendsampleids = trList.eq(row).attr("sendsampleids");
   var between = trList.eq(row).attr("between");//
   var method = trList.eq(row).attr("method");//
   var method_ids = trList.eq(row).attr("method_ids");//
}

//初始化tr上面的行数,row
function init_row(){
   var trList = $("table#taskList tbody tr");
   for(var i=0;i<trList.size();i++){
      var tr = $(trList).eq(i);
      $(tr).attr("row",i);
   }
}



可以使用parent

//初始化删除按钮操作
function init_del_click() {
    var delList = $("#post_content").find("button#del");
    console.log("delList长度::" + delList.size());
    $(delList).click(function () {
        console.log($(this));
        //执行删除本行操作
        $(this).parent().parent().remove();
        //执行删除本行操作parent
    });
}


var itemList = $("#post_content").find("div.layui-form-item");
var row_num = 1;//提示用户的时候用。
var json_str = "[";
for(var i=0;i<itemList.size();i++){
    var item = $(itemList).get(i);
    var item_file_path = $(item).attr("file_path");
    var input_guige = $(item).find("input#guige");
    var input_biaozhun = $(item).find("input#biaozhun");
    var input_num = $(item).find("input#num");
    var guige = $(input_guige).val();
    var biaozhun = $(input_biaozhun).val();
    var num = $(input_num).val();
    guige =  guige.replace(" ","");
    biaozhun =  biaozhun.replace(" ","");
    num =  num.replace(" ","");
    //判断num是数字
    }





如何快速使用java格式化json 字符串, 如何解析json字符串。

{"OrderNumber":"ECI2019120414535273204025","Paging":{"PageSize":10,"PageIndex":1,"TotalRecords":65},"Result":[{"KeyNo":"9cce0780ab7644008b73bc2120479d31","Name":"小米科技有限责任公司","OperName":"雷军","StartDate":"2010-03-03 00:00:00","Status":"在业","No":"110108012660422","CreditCode":"91110108551385082Q"},{"KeyNo":"02ff6e6bed57a655db1bc67dfa829984","Name":"广东小米科技有限责任公司","OperName":"雷军","StartDate":"2015-09-21 00:00:00","Status":"在业","No":"440101000376086","CreditCode":"91440101MA59A5P606"},{"KeyNo":"ccee977823bcb7df647dc3dc137b4412","Name":"小米科技有限责任公司深圳分公司","OperName":"程豪","StartDate":"2012-03-07 00:00:00","Status":"存续","No":"440301106049054","CreditCode":"91440300056178676C"},{"KeyNo":"1b12f7bc801cb2aeb99d29598af91db5","Name":"小米科技有限责任公司厦门分公司","OperName":"黎万强","StartDate":"2012-06-21 00:00:00","Status":"存续","No":"350203280036206","CreditCode":"91350203094247302B"},{"KeyNo":"6960159df579c85e194537307f410b6f","Name":"小米科技有限责任公司重庆分公司","OperName":"黎万强","StartDate":"2012-04-23 00:00:00","Status":"存续","No":"500901300031169","CreditCode":"91500103595160475E"},{"KeyNo":"2fbb8756bf482205e4591a5ff78d80a5","Name":"小米科技有限责任公司天津南开分公司","OperName":"黎万强","StartDate":"2014-04-29 00:00:00","Status":"存续","No":"120104000275380","CreditCode":"9112010430032623XE"},{"KeyNo":"e54fa531bb62c3931cba7d10206c1bc7","Name":"深圳小米米科技有限责任公司","OperName":"郭来力","StartDate":"2014-04-16 00:00:00","Status":"存续","No":"440301109172378","CreditCode":"914403000943323397"},{"KeyNo":"ad622acd512e8f07fb287627b6901a7d","Name":"西藏小米科技有限责任公司","OperName":"雷军","StartDate":"2012-10-29 00:00:00","Status":"注销","No":"540091100001322","CreditCode":""},{"KeyNo":"67c153c5baa013aea159f1f3d85e7115","Name":"唐山小米科技有限责任公司","OperName":"王卿","StartDate":"2019-07-26 00:00:00","Status":"存续","No":"","CreditCode":"91130223MA0DWHMQ2R"},{"KeyNo":"e9e467a49d23f30d9feaf4c651fa71b9","Name":"甘肃小米智能科技有限责任公司","OperName":"王小龙","StartDate":"2017-11-23 00:00:00","Status":"存续","No":"620702200093937","CreditCode":"91620702MA733ATW2H"}],"Status":"200","Message":"查询成功"}}






public class TestJson {

	public static void main(String[] args) {
		
		String jsonString = "[{\"KeyNo\":\"9cce0780ab7644008b73bc2120479d31\",\"Name\":\"小米科技有限责任公司\",\"OperName\":\"雷军\",\"StartDate\":\"2010-03-03 00:00:00\",\"Status\":\"在业\",\"No\":\"110108012660422\",\"CreditCode\":\"91110108551385082Q\"},{\"KeyNo\":\"02ff6e6bed57a655db1bc67dfa829984\",\"Name\":\"广东小米科技有限责任公司\",\"OperName\":\"雷军\",\"StartDate\":\"2015-09-21 00:00:00\",\"Status\":\"在业\",\"No\":\"440101000376086\",\"CreditCode\":\"91440101MA59A5P606\"},{\"KeyNo\":\"ccee977823bcb7df647dc3dc137b4412\",\"Name\":\"小米科技有限责任公司深圳分公司\",\"OperName\":\"程豪\",\"StartDate\":\"2012-03-07 00:00:00\",\"Status\":\"存续\",\"No\":\"440301106049054\",\"CreditCode\":\"91440300056178676C\"},{\"KeyNo\":\"1b12f7bc801cb2aeb99d29598af91db5\",\"Name\":\"小米科技有限责任公司厦门分公司\",\"OperName\":\"黎万强\",\"StartDate\":\"2012-06-21 00:00:00\",\"Status\":\"存续\",\"No\":\"350203280036206\",\"CreditCode\":\"91350203094247302B\"},{\"KeyNo\":\"6960159df579c85e194537307f410b6f\",\"Name\":\"小米科技有限责任公司重庆分公司\",\"OperName\":\"黎万强\",\"StartDate\":\"2012-04-23 00:00:00\",\"Status\":\"存续\",\"No\":\"500901300031169\",\"CreditCode\":\"91500103595160475E\"},{\"KeyNo\":\"2fbb8756bf482205e4591a5ff78d80a5\",\"Name\":\"小米科技有限责任公司天津南开分公司\",\"OperName\":\"黎万强\",\"StartDate\":\"2014-04-29 00:00:00\",\"Status\":\"存续\",\"No\":\"120104000275380\",\"CreditCode\":\"9112010430032623XE\"},{\"KeyNo\":\"e54fa531bb62c3931cba7d10206c1bc7\",\"Name\":\"深圳小米米科技有限责任公司\",\"OperName\":\"郭来力\",\"StartDate\":\"2014-04-16 00:00:00\",\"Status\":\"存续\",\"No\":\"440301109172378\",\"CreditCode\":\"914403000943323397\"},{\"KeyNo\":\"ad622acd512e8f07fb287627b6901a7d\",\"Name\":\"西藏小米科技有限责任公司\",\"OperName\":\"雷军\",\"StartDate\":\"2012-10-29 00:00:00\",\"Status\":\"注销\",\"No\":\"540091100001322\",\"CreditCode\":\"\"},{\"KeyNo\":\"67c153c5baa013aea159f1f3d85e7115\",\"Name\":\"唐山小米科技有限责任公司\",\"OperName\":\"王卿\",\"StartDate\":\"2019-07-26 00:00:00\",\"Status\":\"存续\",\"No\":\"\",\"CreditCode\":\"91130223MA0DWHMQ2R\"},{\"KeyNo\":\"e9e467a49d23f30d9feaf4c651fa71b9\",\"Name\":\"甘肃小米智能科技有限责任公司\",\"OperName\":\"王小龙\",\"StartDate\":\"2017-11-23 00:00:00\",\"Status\":\"存续\",\"No\":\"620702200093937\",\"CreditCode\":\"91620702MA733ATW2H\"}]";
		System.out.println(jsonString);
		
		JSONArray array = JSONArray.fromObject(jsonString);
		System.out.println(array.size());
		
		for(int i=0;i<array.size();i++) {
			JSONObject item =  (JSONObject) array.get(i);
			//System.out.println(item);
			System.out.println(item.getString("Name"));
			System.out.println(item.getString("CreditCode"));
		}
		
		
	}
	
	
	public static void name() {
		
		String jsonString = "{\"OrderNumber\":\"ECI2019120414535273204025\",\"Paging\":{\"PageSize\":10,\"PageIndex\":1,\"TotalRecords\":65},\"Result\":[{\"KeyNo\":\"9cce0780ab7644008b73bc2120479d31\",\"Name\":\"小米科技有限责任公司\",\"OperName\":\"雷军\",\"StartDate\":\"2010-03-03 00:00:00\",\"Status\":\"在业\",\"No\":\"110108012660422\",\"CreditCode\":\"91110108551385082Q\"},{\"KeyNo\":\"02ff6e6bed57a655db1bc67dfa829984\",\"Name\":\"广东小米科技有限责任公司\",\"OperName\":\"雷军\",\"StartDate\":\"2015-09-21 00:00:00\",\"Status\":\"在业\",\"No\":\"440101000376086\",\"CreditCode\":\"91440101MA59A5P606\"},{\"KeyNo\":\"ccee977823bcb7df647dc3dc137b4412\",\"Name\":\"小米科技有限责任公司深圳分公司\",\"OperName\":\"程豪\",\"StartDate\":\"2012-03-07 00:00:00\",\"Status\":\"存续\",\"No\":\"440301106049054\",\"CreditCode\":\"91440300056178676C\"},{\"KeyNo\":\"1b12f7bc801cb2aeb99d29598af91db5\",\"Name\":\"小米科技有限责任公司厦门分公司\",\"OperName\":\"黎万强\",\"StartDate\":\"2012-06-21 00:00:00\",\"Status\":\"存续\",\"No\":\"350203280036206\",\"CreditCode\":\"91350203094247302B\"},{\"KeyNo\":\"6960159df579c85e194537307f410b6f\",\"Name\":\"小米科技有限责任公司重庆分公司\",\"OperName\":\"黎万强\",\"StartDate\":\"2012-04-23 00:00:00\",\"Status\":\"存续\",\"No\":\"500901300031169\",\"CreditCode\":\"91500103595160475E\"},{\"KeyNo\":\"2fbb8756bf482205e4591a5ff78d80a5\",\"Name\":\"小米科技有限责任公司天津南开分公司\",\"OperName\":\"黎万强\",\"StartDate\":\"2014-04-29 00:00:00\",\"Status\":\"存续\",\"No\":\"120104000275380\",\"CreditCode\":\"9112010430032623XE\"},{\"KeyNo\":\"e54fa531bb62c3931cba7d10206c1bc7\",\"Name\":\"深圳小米米科技有限责任公司\",\"OperName\":\"郭来力\",\"StartDate\":\"2014-04-16 00:00:00\",\"Status\":\"存续\",\"No\":\"440301109172378\",\"CreditCode\":\"914403000943323397\"},{\"KeyNo\":\"ad622acd512e8f07fb287627b6901a7d\",\"Name\":\"西藏小米科技有限责任公司\",\"OperName\":\"雷军\",\"StartDate\":\"2012-10-29 00:00:00\",\"Status\":\"注销\",\"No\":\"540091100001322\",\"CreditCode\":\"\"},{\"KeyNo\":\"67c153c5baa013aea159f1f3d85e7115\",\"Name\":\"唐山小米科技有限责任公司\",\"OperName\":\"王卿\",\"StartDate\":\"2019-07-26 00:00:00\",\"Status\":\"存续\",\"No\":\"\",\"CreditCode\":\"91130223MA0DWHMQ2R\"},{\"KeyNo\":\"e9e467a49d23f30d9feaf4c651fa71b9\",\"Name\":\"甘肃小米智能科技有限责任公司\",\"OperName\":\"王小龙\",\"StartDate\":\"2017-11-23 00:00:00\",\"Status\":\"存续\",\"No\":\"620702200093937\",\"CreditCode\":\"91620702MA733ATW2H\"}],\"Status\":\"200\",\"Message\":\"查询成功\"}";
		System.out.println(jsonString);
		
		JSONObject obj  = JSONObject.fromObject(jsonString);
		
		System.out.println(obj.getString("OrderNumber"));
		System.out.println(obj.getInt("Status"));
		System.out.println(obj.getString("Message"));
		
		JSONObject PagingObj = obj.getJSONObject("Paging");
		System.out.println(PagingObj);
		System.out.println(PagingObj.getInt("PageSize"));
		
		JSONArray resultArray = obj.getJSONArray("Result");
		System.out.println(resultArray.size());
		
		for(int i=0;i<resultArray.size();i++) {
			JSONObject item =  (JSONObject) resultArray.get(i);
			//System.out.println(item);
			System.out.println(item.getString("Name"));
			System.out.println(item.getString("CreditCode"));
		}
		
		
		
	}
	

}


联系站长

站长微信:xiaomao0055

站长QQ:14496453