jqueryメソッドの収集と照合の実際の開発

1つは、バッチオブジェクトパラメータをajaxを介してバックグラウンドに渡すことです。

フロントエンド:

var selectType = [];
var point = {
            tableName: 'T_CSBJXXB',
            type: bjbm,
            dataArea: dataAreaCode
        }

selectType.push(point);
//多个对象就向selectType 数组内推入多个point对象
$.ajax({
            type : "POST",
            dataType : 'json',
            url : "/PowerOfManagement/getpointByAreacode",
            //将批量对象selectType数组转成字符串,后台以string类型接收
            data : {'str':JSON.stringify(selectType),'pageSize':0,'pageNum':0},
            success : function(data) {
                if (data.success) {
                    
                }
            },
            error : function() {
                console.log("请求出错,请联系管理员!");
            }
        });

舞台裏:

JSONオブジェクトはcom.alibaba.fastjsonパッケージに属していることに注意してください

前の段落で変換されたstrの形式は次のとおりです。 

"[{" tableName ":" T_BMLLXXB "、" type ":" 0 | 1 | 2 "、" dataArea ":" 320505 "}、{" tableName ":" T_JKXXB "、" type ":" 0 | 1 | 2 "、" dataArea ":" 320505 "}]"

 @RequestMapping(value = "getpointByAreacode", method = RequestMethod.POST)
    public void getpointByAreacode(HttpServletRequest request, HttpServletResponse response, String str,int pageSize,int pageNum){
        Result result = new Result();
        try {
            // fastjson将字符串转换成对象集合
            List<PointOfManagementPower> list =                                                         
                                  JSON.parseArray(selectType,PointOfManagementPower.class);
            result.setMessage("查询成功");
            result.setSuccess(true);
            result.setList(list );
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("获取失败!"+e);
        }

        this.print(result.toString(),response);
    }

2、jq検索ステートメント

//area-code是页面上一直有的,不要动态拼接的元素
//查找area-code下的 button标签内的 role属性以town开头的 a标签的value值
// find查找不只子类,孙子类,重孙子类等等向下都内查到
$("#area-code").find("button a[role^='town']").attr("value");




//向上一级一级查找到class为btn-parent-div的父元素,然后再找内部checkbox的标签集合,并遍历
//checkbox在我这里是动态拼接内的标签,判断选中不能用直接attr('check')判断,要用is函数
//修改属性要用prop方法
$(this).parent().parent().parent().parent().parent().parent(".btn-parent-div").find("input[type='checkbox']").each(function () {
                //这里的this对象是遍历的每一个input[type='checkbox']对象,而不是开头的this对象
                if ($(this).is(":checked")) {
                    $(this).prop("checked", false);
                }
            })
//选中
 $(this).prop("checked", true);


$(this).parent().parent().parent().parent().parent().addClass("btn-primary");
                    $(this).parent().parent().parent().parent().parent().removeClass("btn-warning");

3、jqのイベント

//鼠标滚轮滚动事件  据说兼容性很高
 $("#mapDiv").on("mousewheel DOMMouseScroll",function (e) {
        // console.log("666");
        //判断滚动方向
        //chrome & ie || Firefox   区分浏览器
        var delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ?1 :-1)) 
            || (e.originalEvent.detail && (e.originalEvent.detail > 0 ? -1 : 1));//Firefox                                                                         

    
    if (delta > 0) {
        // 向上滚
        console.log("wheelup");
    } else if (delta < 0) {
        // 向下滚
        console.log("wheeldown");
    }
    });


//绑定点击事件
//input[type='checkbox']是我动态拼接到内部的 .select-type-list-city-sec固定存在
$(".select-type-list-city-sec").on("click","input[type='checkbox']",function (e) { 
//这里的this对象是点击的input[type='checkbox'],而不是.select-type-list-city-sec
$(this).parent();
})


//点击事件li a标签也是动态拼接到area-code内部的
 $("#area-code").on("click","li a[role^='town']",function () {
//获取a标签的value属性  this对象是a标签
        var code = $(this).attr("value");
})

 

おすすめ

転載: blog.csdn.net/tonglei111/article/details/98057282