JS多个函数之间传递参数问题

  JS多个函数之间传递参数的一个重要思想是在页面定义一个隐藏域,当第一个函数请求到数据时候修改隐藏域的值,第二个函数用jQuery的选择器选择页面中隐藏域的值。

比如:

页面中定义一个隐藏的页号。

<!-- 隐藏查询条件的页号 -->
                                    <input type="hidden" name="currentPage" id="currentPage">

第一个ajax函数获取页面中的页号:

function queryNum(checkunit, dangergrade, type) {
    alert("点击查询按钮条件" + checkunit + " " + dangergrade + " " + type);
    $.ajax({
        url : "/danger/queryDangerTongji.action",
        async : true,
        data : {
            "currentPage" : $("#currentPage").val(), // 查询隐藏的页号
            "checkunit" : checkunit,
            "dangergrade" : dangergrade,
            "type" : type
        },
        dataType : "text",
        type : "POST",
        success : showTable,
        error : function() {
            alert("请求失败!");
        }

    });
}

第二个函数给隐藏的页号赋值(下次点击页号的时候就可以通过一个隐藏域获取到值)

function page(currentPage, totalCount, checkunit, type, dangergrade) {
    // 修改分页的基本属性
    $('#paginationIDU1').pagination(
            {
                // 组件属性
                "total" : totalCount,// 数字 当分页建立时设置记录的总数量 1
                "pageSize" : 8,// 数字 每一页显示的数量 10
                "pageNumber" : currentPage,// 数字 当分页建立时,显示的页数 1
                "pageList" : [ 8 ],// 数组 用户可以修改每一页的大小,
                // 功能
                "layout" : [ 'list', 'sep', 'first', 'prev', 'manual', 'next',
                        'last', 'links' ],
                "onSelectPage" : function(pageNumber, b) {
                    alert("查询后条件:" + currentPage + "    " + totalCount + "    "
                            + checkunit + "    " + type + "    " + dangergrade);
                    // queryNum(checkunit, dangergrade, type, currentPage);
                    $("#currentPage").val(pageNumber);
                    alert($("#currentPage").val());// 向页面的隐藏域设置一个值
                    queryNum(checkunit, type, dangergrade);
                }
            });
}

另外:在传递字符串参数的时候需要加引号,在JS拼接的时候也需要加引号

例如:

"<a class='button' href=javascript:void(0) onclick='deleteCw(""+list[i]+"")'><span class='glyphicon glyphicon-trash'></span></a>"

"代表转义字符,结果是作为"处理。

原文地址:https://www.cnblogs.com/qlqwjy/p/7492306.html