我需要从js获取我的观点的类名。
说我的网址是
http://localhost/test/index.php/mytest/newtest/34
这里newtest是视图类的名称。我想从我的js获得这个类名。 我在谷歌搜索过它,但没有找到任何有用的东西。
提前致谢。
答案 0 :(得分:2)
var pathArray = window.location.pathname;
pathArray = pathArray.replace(/^\/|\/$/g, '');
pathArray = pathArray.split( '/' );
console.log(pathArray);
使用此Javascript,您将从您的网址获取所有部分作为数组。在那里,您将知道您正在寻找的元素。