已知
<script language='javascript'>
var url = this.location.href;
</script>
<a href="这里是JS里面获取的当前页面地址">地址</a>
应该怎么才能输出
document.write这样是没法输入到HTML文本,a标记已经固定的HTML 所以不能用这个
我的代码是这样的
<div class="app-btns">
<ul>
<li class="apphh"><a href="这里是JS里面获取的当前页面地址
#apphhdown" >地址
</a></li>
</ul>
</div>
<a href 应该写到js中.
<script language='javascript'>var url = this.location.href;
document.write("<a href='"+url+"'>地址</a>");
</script>追问
就是不知道写输出,
追答已经给你写出js代码。
追问谢谢,这个输出没法插入到指定位置。我的a 标签是有div的
追答<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<script language='javascript'>
var url = this.location.href;
</script>
</head>
<body>
<div class="app-btns">
<ul>
<li class="apphh">
<div class="app-btns">
<ul>
<li class="apphh">
<a id="a" href="">地址</a><!--这里加个id=a -->
</li></ul>
</div>
<script>document.getElementById("a").href=url;</script>
</body>
</html>
你同样可以用document.write 的,代码如下
<div class="app-btns"><ul>
<li class="apphh"><!--下面加js不影响的--!>
<script>document.write("<a href='"+url+"'>地址</a>")</script>
</li></ul>
</div>追问
谢谢 效果是达到了,我想在地址后面加一个 #abc 怎么加,刚刚试了一下没加成功
追答document.write("地址")
document.getElementById("a").href=url+"#abc";
温馨提示:答案为网友推荐,仅供参考
第1个回答 2014-10-28
document.links[0].href = url;
document.links[0].innerText = url;追问
<head>
<meta charset="utf-8" />
<title>b.html</title>
<style type="text/css">
</style>
<script type="text/javascript">
window.onload = function ()
{
var url = this.location.href;
document.links[0].href = url;
document.links[0].innerText = url;
}
</script>
</head>
<body>
<a href="这里是JS里面获取的当前页面地址">地址</a>
</body>
</html>追问
document.links[0].innerText = url;追问
结果如何呈现在HTML里面?
追答<html><head>
<meta charset="utf-8" />
<title>b.html</title>
<style type="text/css">
</style>
<script type="text/javascript">
window.onload = function ()
{
var url = this.location.href;
document.links[0].href = url;
document.links[0].innerText = url;
}
</script>
</head>
<body>
<a href="这里是JS里面获取的当前页面地址">地址</a>
</body>
</html>追问
我的代码是这样的
地址