javascript中的多锚标记href值
我正在动态创建多个锚定标记。我想在javascript中获取单击锚定标记的href值。我使用下面的代码来实现这一点 javascriptjavascript中的多锚标记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
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上