要实现的功能:<div id="href_false" 里的链接默认失效,当触发function href_true() 以后,链接生效,可以正常点开
要求,只能在function href_true() 里写入代码,不能在<a>里写入代码,最多在div里写入代码<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<script language="javascript">
<!--
function href_true()
{
}
//-->
</script></head><body>
<div id="href_false" onclick="return false;"> <a href="http://www.baidu.com" >www.baidu.com][csdn]csdn社区</a><div><input type="button" onclick=href_true() id="btn" value="接触锁定" /></body></html>
要求,只能在function href_true() 里写入代码,不能在<a>里写入代码,最多在div里写入代码<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<script language="javascript">
<!--
function href_true()
{
}
//-->
</script></head><body>
<div id="href_false" onclick="return false;"> <a href="http://www.baidu.com" >www.baidu.com][csdn]csdn社区</a><div><input type="button" onclick=href_true() id="btn" value="接触锁定" /></body></html>
不能在<a>里写入代码,
实在不行可以在div里写入代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<style>
</style>
</head>
<body>
<div id="test"><a href="http://baidu.com">百度</a></div>
<script>
function $(o){return document.getElementById(o)}
$('test').onclick = function(){
window.open('http://www.google.com.hk/');
return false;
}
</script>
</body>
</html>
这个意思?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<style>
</style>
</head>
<body>
<div id="test"><a href="http://baidu.com">百度</a></div>
<script>
function $(o){return document.getElementById(o)}
$('test').onclick = href_true;
function href_true(){
window.open('http://www.google.com.hk/');
return false;
}
</script>
</body>
</html>变一下就可以了。
window.open('http://www.google.com.hk/');这个链接无法固定出现在代码里,你怎么捕获?
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<script language="javascript">
<!--
function $(o){return document.getElementById(o)}
function href_true()
{
var obj = $('href_false').getElementsByTagName('a')[0]
window.open(obj.href)
}
//-->
</script></head><body>
<div id="href_false" onclick="return false;"> <a href="http://www.baidu.com" >www.baidu.com][csdn]csdn社区</a><div><input type="button" onclick=href_true() id="btn" value="接触锁定" /></body></html>
触发函数后,链接变为正常可以点击,就是和正常的链接没什么二样,而不是弹出window.open(obj.href)
需要修改
function href_true()
{
document.getElementById("href_false").onclick = null;
}
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<script language="javascript">
<!--
function $(o){return document.getElementById(o)}
function href_true()
{
$('href_false').setAttribute('onclick','');
}
//-->
</script></head><body>
<div id="href_false" onclick="return false;"> <a href="http://www.baidu.com" >www.baidu.com][csdn]csdn社区</a><div><input type="button" onclick=href_true() id="btn" value="接触锁定" /></body></html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Jquery Animate</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<script type="text/javascript">
function href_true()
{
$("#href_false").removeAttr("onclick");
}
</script>
</head>
<body><div id="href_false" onclick="return false;" ><a href="http://www.baidu.com">www.baidu.com</a></div><input type="button" onclick='href_true()' id="btn" value="接触锁定" /></body>
</html>