首页 > 代码库 > 点击div 跳转并通过URL传参

点击div 跳转并通过URL传参

点击div前要先给div绑定要传的参数:

//给panel绑定自定义属性,方便在跳转时传带参数,键/值对排列
        panel.attr("user_age",user_age);
        panel.attr("user_name",user_name);
        panel.attr("user_sex",user_sex);
        panel.attr(‘user_problem_dec‘,user_problem_dec);
        panel.attr(‘user_img_src‘,img_src);

点击动作发生时,要把绑定的参数的值取出来,以URL传参的方式传递参数

//根据data-id跳转
    $(‘div[data-id = problemList]‘).click(function() {
        //取出绑定的自定义属性的值
        var userName = $(this).attr("user_name");
        var userAge = $(this).attr("user_age");
        var userSex = $(this).attr("user_sex");
        var userProblemDec = $(this).attr(‘user_problem_dec‘);
        var userImgSrc = http://www.mamicode.com/$(this).attr(‘user_img_src‘);
        window.location.href = "doctor_ask_problem.html?userId=" + ‘aaaa‘ + ‘&userName=‘ + userName + ‘&userAge=‘ + userAge + ‘&userSex=‘ + userSex + ‘&userProblemDec=‘ + userProblemDec;
    });

 

点击div 跳转并通过URL传参