为啥第三种方式不能进行跳转

问题相关代码,请勿粘贴截图

register1= function (){
//window.location.href="<%=request.getContextPath()%>/register.jsp"
window.location.href="<%=request.getContextPath()%>"+"/register.jsp" //字符串拼接可以进行跳转
window.location.href=<%=request.getContextPath()%>+"/register.jsp" //为啥这种不行
}

你的第三种方法中<%=request.getContextPath()%>这一串不符合前端数据类型。你要不加个String(<%=request.getContextPath()%>)包着试试

第三个这样不是字符串吧,没报错?