<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。

解决方案 »

  1.   

    没用 jQuery,纯 jsL@_@K
    <!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>
      

  2.   

    FF 不支持 click() 方法改下,L@_@K<!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>
      

  3.   

    我的目的是,
    单击某一元素,可以转向一个 指定 超链接标签的的超链接。但这个超链接,可能是是 _top,可能是iframe。
      

  4.   

    lz 用 #4 代码吧,IE 7 和 FF 3 测试通过!#2 代码 IE 可用, FF 下无效!
      

  5.   

    转向已经解决了,定位问题要看具体应用 window.top.location.href 或 document.frames[i].src!
      

  6.   

    首先yixianggao所说的object.click();在FF中的确是不存在。
    只有模拟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;
    };
    没测试,不好意思
      

  7.   

    触发不触发单击是次要,重要的是,转向!但这个转向,存在“多义”。
    可能是:<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 楼。