<button id="btn_test">尝试</button>
<a href="http://www.g.cn" id="a_test">谷歌</a>$(function()
{
$("#btn_test").click(function()
{
$("#a_test").click();
});
});并没有实现转向,如何解决?不要获取 #a_test 的href 值,因为他的链接指向一个 iframe。
<a href="http://www.g.cn" id="a_test">谷歌</a>$(function()
{
$("#btn_test").click(function()
{
$("#a_test").click();
});
});并没有实现转向,如何解决?不要获取 #a_test 的href 值,因为他的链接指向一个 iframe。
<!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> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head> <body>
<button id="btn_test">尝试</button>
<a href="http://www.g.cn" id="a_test">谷歌</a>
<script type="text/javascript">
<!--
function $(sId) {
return document.getElementById(sId);
}$("btn_test").onclick = function() {
$("a_test").click();
};
//-->
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head> <body>
<button id="btn_test">尝试</button>
<a href="http://www.g.cn" id="a_test">谷歌</a>
<script type="text/javascript">
<!--
function $(sId) {
return document.getElementById(sId);
}$("btn_test").onclick = function() {
window.location.href = $("a_test").href;
};
//-->
</script>
</body>
</html>
单击某一元素,可以转向一个 指定 超链接标签的的超链接。但这个超链接,可能是是 _top,可能是iframe。
只有模拟click事件来达到跳转,首先是跳转
target.location.href = href;
其次是目标也就是targetfunction getTarget(obj){
var win=window;
if(obj.tagName!="A")return;
var tgStr=$("a_test").target;
if(tgStr==null||tgStr=="")return window;
else{
win=getFrameByName(tgStr);
win=(win!=null)?win:window;
}
}获取Frame
function getFrameByName(name){
var a = window.document.getElementsByTagName("IFRAME");
for(var i=0;i<a.length;i++){
if(a[i].name==name)return a[i];
}
return null;
}
最后跳转方法
$("btn_test").onclick = function() {
var aLink=$("a_test");
var win=getTarget(aLink);
win.location.href = aLink.href;
};
没测试,不好意思
可能是:<a href="/index.aspx#cont"> 链接A </a>
<a href="http://g.cn" target="_top"> 链接B </a>
<a href="/index.aspx#cont" target="ContIframe"> 链接B </a>我试一下 9 楼。