欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

​js怎么获取当前页面文件名 有大用

js怎么获取当前页面文件名?

<script>alert(window.location.href);</script>↑不是这种不是当前页面的详细地址~而是文件名就可以了比如我当前页面在http://www.baidu.com/a.php那么代表当前页面的文件名是:a.php...展开
 我来答  举报
幻翼高达Zero
2019-07-03

需要准备的材料分别有:电脑、html编辑器、浏览器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<script>标签,输入js代码:var a = location.href.split('/');document.body.innerText = a[a.length - 1];。

3、浏览器运行index.html页面,此时成功获取到当前页面文件名index.html并打印了出来。

haoqinhu1314
2015-10-17
就用你说的方法,我写的例子如下:

<form>
<input type=text name=xxx><input type=submit>
</form>
<script language=javascript>
document.writeln(location.href,'<br>');
var s=location.href;
s=s.replace(/\?.*$/,'')
s=s.replace(/^.*\//,'')
document.writeln(s,'<br>');
</script>


来自  https://zhidao.baidu.com/question/59821246.html

普通分类: