js里,一个页面中两个不同位置的按钮,分别点击跳转到同一个页面

复制的是项目中的源码 ,请忽略中间部分

页面中的第二个按钮

<a href="#" class="btn-xs btn-info js-inCheck" >进入检测</a>

  页面第一个按钮js-btnStart跳转

/*开始检测*/
    $('.js-btnStart').on('click',function(){
 

        var name = $('.iptcjName').val().trim();
        var user = $('.iptcjUser').val().trim();
        var scope_long=$('.w_range').val().trim();
        var scope_wide=$('.h_range').val().trim();
     

        if(!name){                                                                                                    // 判断input输入框的输入值是否为空
            $('.js-box-scene .iptcjName').next('.ipterr').html('检测名称不能为空');
            return false;
        }else{
            $('.js-box-scene .iptcjName').next('.ipterr').html('');
        }

        if(!user){
            $('.js-box-scene .iptcjUser').next('.ipterr').html('操作人不能为空');
            return false;
        }else{
            $('.js-box-scene .iptcjUser').next('.ipterr').html('');
        }
        // if(!_lon_lat.IsCoordinate()){
        //     $('.iptlon_lat').next('.ipterr').html('坐标格式不正确');
        //     return false;
        // }else{
        //     $('.iptlon_lat').next('.ipterr').html('');
        // }

        if(scope_long && scope_wide){
            $('.h_range').next('.ipterr').html('');
        }else{
            $('.h_range').next('.ipterr').html('输入格式不正确');
            return false;
        }
        if(!isDigit(scope_long) || !isDigit(scope_wide)){
            return false;
        }
  
        $.ajax({
            url:'/movecheck/addDetectionScene',
            type:'post',
            data:{
                name:name,
                scope_long:scope_long,
                scope_wide:scope_wide,
                // lat:lat,
                // lon:lon,
                user:user
            },
            success:function(dt){
                if(dt.result){
                    $('.layer').remove();
                    // window.location.href='/movecheck/inner';
                    window.open('/movecheck/inner',name);      在这儿使用window。open 并且在url 后面加入一个name属性
                }else{
                    createPrompt('error',dt.err_msg,true);
                }
            },
            error:function(error){
                console.log(error)
                createPrompt('error','开始检测失败',true);
            }
        });
        $(".js-box-scene").hide();
    });
 

页面第二个按钮.js-inCheck'跳转

//进入检测按钮
    $(document).on('click','.js-inCheck',function(){
        var name=$(this).attr("data-name");
        // window.open('/movecheck/inner');
        window.open('/movecheck/inner',name);      在这儿也使用window.open 也加入一个name属性,就能保证两次跳转进入的是同一个页面

    });

猜你喜欢

转载自blog.csdn.net/qq_42177730/article/details/81198066