Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript中的多锚标记href值_Javascript_Jsp - Fatal编程技术网

javascript中的多锚标记href值

javascript中的多锚标记href值,javascript,jsp,Javascript,Jsp,我正在动态创建多个锚定标记。我想在javascript中获取单击锚定标记的href值。我使用下面的代码来实现这一点 javascript document.getElementById("aaa").href <a id="aaa" onclick="follow(this);" href="sec/IF 00.html">Hi</a> <a id="aaa" onclick="follow(this);" href="sec/IF 002.html"&g

我正在动态创建多个锚定标记。我想在javascript中获取单击锚定标记的href值。我使用下面的代码来实现这一点

javascript

document.getElementById("aaa").href

<a id="aaa" onclick="follow(this);" href="sec/IF   00.html">Hi</a>
<a id="aaa" onclick="follow(this);" href="sec/IF   002.html">Hi</a>
请尝试以下代码:

function follow(item) {
    alert(item.href);
}
更新

但您必须禁用本机链接
单击
触发:

html:

而且您根本不必使用
id
属性

更新2

完整代码:

<!DOCTYPE html>
<html>
<head>
<script>
function follow(e, item) {
    e = e || window.event;  //IE stuff
    e.preventDefault();     //prevent link click triggering
    e.returnValue = false;  //also prevent link click triggering (old IE style)
    alert(item.getAttribute('href'));
}
</script>
</head>
<body>

<a onclick="follow(event, this);" href="sec/IF00.html">Hi</a>
<a onclick="follow(event, this);" href="sec/IF002.html">Hi</a>

</body>
</html>

职能跟进(e,项目){
e=e | | window.event;//IE文件
e、 preventDefault();//防止链接单击触发
e、 returnValue=false;//还防止链接单击触发(旧IE样式)
警报(item.getAttribute('href');
}
尝试以下代码:

function follow(item) {
    alert(item.href);
}
更新

但您必须禁用本机链接
单击
触发:

html:

而且您根本不必使用
id
属性

更新2

完整代码:

<!DOCTYPE html>
<html>
<head>
<script>
function follow(e, item) {
    e = e || window.event;  //IE stuff
    e.preventDefault();     //prevent link click triggering
    e.returnValue = false;  //also prevent link click triggering (old IE style)
    alert(item.getAttribute('href'));
}
</script>
</head>
<body>

<a onclick="follow(event, this);" href="sec/IF00.html">Hi</a>
<a onclick="follow(event, this);" href="sec/IF002.html">Hi</a>

</body>
</html>

职能跟进(e,项目){
e=e | | window.event;//IE文件
e、 preventDefault();//防止链接单击触发
e、 returnValue=false;//还防止链接单击触发(旧IE样式)
警报(item.getAttribute('href');
}
尝试以下代码:

function follow(item) {
    alert(item.href);
}
更新

但您必须禁用本机链接
单击
触发:

html:

而且您根本不必使用
id
属性

更新2

完整代码:

<!DOCTYPE html>
<html>
<head>
<script>
function follow(e, item) {
    e = e || window.event;  //IE stuff
    e.preventDefault();     //prevent link click triggering
    e.returnValue = false;  //also prevent link click triggering (old IE style)
    alert(item.getAttribute('href'));
}
</script>
</head>
<body>

<a onclick="follow(event, this);" href="sec/IF00.html">Hi</a>
<a onclick="follow(event, this);" href="sec/IF002.html">Hi</a>

</body>
</html>

职能跟进(e,项目){
e=e | | window.event;//IE文件
e、 preventDefault();//防止链接单击触发
e、 returnValue=false;//还防止链接单击触发(旧IE样式)
警报(item.getAttribute('href');
}
尝试以下代码:

function follow(item) {
    alert(item.href);
}
更新

但您必须禁用本机链接
单击
触发:

html:

而且您根本不必使用
id
属性

更新2

完整代码:

<!DOCTYPE html>
<html>
<head>
<script>
function follow(e, item) {
    e = e || window.event;  //IE stuff
    e.preventDefault();     //prevent link click triggering
    e.returnValue = false;  //also prevent link click triggering (old IE style)
    alert(item.getAttribute('href'));
}
</script>
</head>
<body>

<a onclick="follow(event, this);" href="sec/IF00.html">Hi</a>
<a onclick="follow(event, this);" href="sec/IF002.html">Hi</a>

</body>
</html>

职能跟进(e,项目){
e=e | | window.event;//IE文件
e、 preventDefault();//防止链接单击触发
e、 returnValue=false;//还防止链接单击触发(旧IE样式)
警报(item.getAttribute('href');
}

ID必须是唯一的。为每个

document.getElementById(“aaa”).href//sec/IF00.html
document.getElementById(“bbb”).href//sec/IF002.html

ID必须是唯一的。为每个

document.getElementById(“aaa”).href//sec/IF00.html
document.getElementById(“bbb”).href//sec/IF002.html

ID必须是唯一的。为每个

document.getElementById(“aaa”).href//sec/IF00.html
document.getElementById(“bbb”).href//sec/IF002.html

ID必须是唯一的。为每个

document.getElementById(“aaa”).href//sec/IF00.html
document.getElementById(“bbb”).href//sec/IF002.html



ID是唯一的值。不能有多个元素具有相同的IDI。我认为向我们展示
follow()
函数的定义是有意义的。顺便说一句,你应该避免href中的空格…首先要提醒你的是,有些地方不太正确,你正在将元素传递给你的
follow()
作为
项目
运行,然后根本不使用
项目
。ID是唯一的值。不能有多个元素具有相同的IDI。我认为向我们展示
follow()
函数的定义是有意义的。顺便说一句,你应该避免href中的空格…首先要提醒你的是,有些地方不太正确,你正在将元素传递给你的
follow()
作为
项目
运行,然后根本不使用
项目
。ID是唯一的值。不能有多个元素具有相同的IDI。我认为向我们展示
follow()
函数的定义是有意义的。顺便说一句,你应该避免href中的空格…首先要提醒你的是,有些地方不太正确,你正在将元素传递给你的
follow()
作为
项目
运行,然后根本不使用
项目
。ID是唯一的值。不能有多个元素具有相同的IDI。我认为向我们展示
follow()
函数的定义是有意义的。顺便说一句,你应该避免href中的空格…首先要提醒你的是,有些地方不太正确,你正在将元素传递给你的
follow()
充当
项目
,然后根本不使用
项目
。@ManishSingh您使用的是什么浏览器?我在Ubuntu上,无法在IE中测试,不幸的是我同时使用chrome和IE。@ManishSingh请尝试使用
item.getAttribute('href')
而不是
item.href
更新了帖子-现在你可以看到完整的代码了,使用Ubuntu ChromeI再次测试了这段代码,我得到了完整的url startng,谢谢你的帮助。这就是我一直在寻找的工作,没有id。@ManishSingh你在使用什么浏览器?我在Ubuntu上,无法在IE中测试,不幸的是我同时使用chrome和IE。@ManishSingh请尝试使用
item.getAttribute('href')
而不是
item.href
更新了帖子-现在你可以看到完整的代码了,使用Ubuntu ChromeI再次测试了这段代码,我得到了完整的url startng,谢谢你的帮助。这就是我一直在寻找的工作,没有id。@ManishSingh你在使用什么浏览器?我在Ubuntu上,无法在IE中测试,不幸的是我同时使用chrome和IE。@ManishSingh请尝试使用
item.getAttribute('href')
而不是
item.href
更新了帖子-现在你可以看到完整的代码了,使用Ubuntu ChromeI再次测试了这段代码,我得到了完整的url startng,谢谢你的帮助。这就是我一直在寻找的工作,没有id。@ManishSingh你在使用什么浏览器?我在Ubuntu上