87,993
社区成员
发帖
与我相关
我的任务
分享<button id="btn_test">尝试</button>
<a href="http://www.g.cn" id="a_test">谷歌</a>$(function()
{
$("#btn_test").click(function()
{
$("#a_test").click();
});
});
function 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;
}
}
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;
};
<!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() {
window.location.href = $("a_test").href;
};
//-->
</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>
<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>