使用jQuery的基本URL [英] base url using jQuery

查看:121
本文介绍了使用jQuery的基本URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在jQuery中获取基本URL?

How to get base url in jQuery?

认为我在 http:// localhost / test / test_controller / test 的js文件然后我只想获得

Think I am in http://localhost/test/test_controller/test's js file then I want to get only

/test

http://localhost/test/


推荐答案

你实际上并不需要使用jQuery。 JavaScript为您提供此功能

You dont actually need to use jQuery. JavaScript provides this for you

var l = window.location;
var base_url = l.protocol + "//" + l.host + "/" + l.pathname.split('/')[1];

这篇关于使用jQuery的基本URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆