本帖最后由 lirko4156 于 2013-05-16 19:45:18 编辑

解决方案 »

  1.   

    类似情况我以前也遇到过,原因是$(function()是在网页加载完成后(不包括iframe加载)立即执行,而此时iframe中的内容可能并未加载完成。解决的办法是让$(function()延时1秒或几秒后执行。
      

  2.   

    这个问题我之前也遇到过,一直没有解决。后来改用Ajax 读取那个页面的制定容器里面的html content了,然后插入到自己的页面中。再CSS定义一下。
      

  3.   


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    </head>
    <body><div id="ad">
    点击id为ad区域内文字内容或a属性等元素生效,点击iframe里面的元素不生效
    <br/><br/><a target="_blank" href="http://www.baidu.com/">点击a属性生效</a>
    <br/><br/>直接iframe显示版
    <br/><br/>
    <iframe id="cproIframe1" src="http://cpro.baidu.com/cpro/ui/uijs.php?rs=0&amp;tu=u470987&amp;tn=text_default_300_250&amp;n=lanrennet2010_cpr&amp;adn=3&amp;rsi1=250&amp;rsi0=300&amp;rad=&amp;rss0=%232F3C45&amp;conBW=0&amp;rss1=%232F3C45&amp;conOP=0&amp;rss2=%2361A7C7&amp;titFF=%25E5%25AE%258B%25E4%25BD%2593&amp;titFS=12&amp;titTA=left&amp;rss3=%23CFE0EE&amp;rss4=%234CB509&amp;rss5=&amp;rss6=%23FF7B0E&amp;rsi5=4&amp;ts=1&amp;at=6&amp;ch=0&amp;cad=1&amp;aurl=&amp;rss7=&amp;cpa=1&amp;fv=11&amp;cn=1&amp;if=16&amp;word=http%3A%2F%2Fwww.bendi.com%2F1.html%23&amp;refer=&amp;ready=1&amp;jk=f3d3d3618bdb60aa&amp;jn=3&amp;lmt=1368672104&amp;csp=1440,900&amp;csn=1440,870&amp;ccd=32&amp;chi=2&amp;cja=true&amp;cpl=38&amp;cmi=94&amp;cce=true&amp;csl=zh-CN&amp;did=1&amp;rt=6&amp;dt=1368700905&amp;ev=50331648&amp;c01=0&amp;prt=1368700905107&amp;i3=f&amp;anatp=0&amp;stid=0&amp;lunum=6" width="300" height="250" align="center,center" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true"></iframe><br/><br/>JS输出iframe显示版
    <br/><br/>
    <script type="text/javascript">
    var cpro_id = 'u470987';</script>
    <script src="http://cpro.baidu.com/cpro/ui/c.js" type="text/javascript"></script></div><script type="text/javascript">
    $(function(){
    $("#ad a").click(function(){
    setTimeout(function(){alert('你点击的id="ad"位置a属性生效了');}, 1000);
    });
    });
    </script>
    </body>
    </html>还是原来的问题没解决..点击框架内的内容不生效
      

  4.   


    你说的Ajax 读取那个页面 而现在不知道页面url地址,因为本身是JS输出iframe,iframe再输出html,Ajax难道能直接读取JS执行后的html代码??
      

  5.   

    在本页面控制iframe内元素的事件,涉及到JS跨域问题。如果iframe的src是外域的,好像没法实现。
    可能有解决方案,但我不知道,只能告诉你会存在跨域问题。
      

  6.   

    你得在iframe里面添加时间,window的层次都不一样,事件肯定就添加不了啊!
      

  7.   

    一个是垮域了,你根本上不能操作iframe里的东西
    二个同域的话,jquery你这样调用只能处理本window的东西,iframe里是另一个window,你要将iframe的document当成一个context传给jquery
      

  8.   


    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
    <style type="text/css">
    * {
    margin:0;
    padding:0;
    }
    html { overflow:hidden; }
    img { border:none; }
    a {
    text-decoration:none;
    color:#000;
    }
    a:hover { color:#F00; }
    a:fouce {
     -moz-outline-style: none;
    }
    a { outline:0; }
    ul li, ol li { list-style:none; }
    h2 { font-size:18px; }
    h3 { font-size:12px; }
    .clear { clear:both; }
    body {
    font-family:Arial, Helvetica, sans-serif;
    font-size:12px;
    color:#000;
    margin:0 auto;
    padding:0 0px;
    height:100%;
    overflow:hidden;
    }
    .inline { display:inline; }
    .of_hidden { overflow:hidden; }
    .f_l {
    float:left;
    display:inline;
    }
    .f_r {
    float:right;
    display:inline;
    }
    .outer {
    height: 500px;
    position:absolute;
    top:50%;
    left:50%;
    margin:-250px 0 0 -400px;;
    width: 800px;
    border:1px dashed #000;
    }
    .ss{height: 25px;
    width: 100px;
    margin:10px;
    position:relative;}
    .button {
    height: 25px;
    width: 100px;
    background:#666;
    border:1px solid #000;
    color:#FFF;
    text-align:center;
    line-height:25px;
    cursor:pointer;
    }.s_h {
    height: 90px;
    width: 90px;
    padding:5px;
    border:1px solid #000;
    position:absolute;
    top:26px;
    background:#CCC;
    display:none;
    left:0;
    }.asdf {
    height: 400px;
    width: 100%;
    border:1px solid #006;
    background:#fff;
    }
    </style>
    </head><body>
    <div class="outer">
    <div tabindex="1" class="ss f_l">
      <div  class="button">展开菜单</div>
        <div  class="s_h">此 处 显 示  菜 单 的 内 容</div>
     </div>
    <div class="asdf f_l">
    <strong class="f_l" style="margin:50px; font-size:30px; margin-top:50px;">如果我在这里 点击 菜单应该关闭,但是在下面的iframe中 点了 没用</strong>
    <iframe class="f_l" style="border:1px dashed #000;" width="100%" frameborder="1" height="300" src="http://www.baidu.com"></iframe>
    </div>
    </div>
    <script type="text/javascript">
    $('.button').click(
    function(){
    $('.s_h').stop(true,true).slideToggle(200);
    }
    );
    $('.ss').blur(function(){$('.s_h').hide()});
    $('.asdf').click(
    function(){
    $('.s_h').slideUp(200);
    }
    );
    </script>
    </body>
    </html>
    对于这个代码用到的能否转移到限点击id="ad"区域才执行吗,现在这个代码点击任意位置都会执行,这不是我想要的效果
      

  9.   

    src="http://www.baidu.com"
    再说一次:跨域了啊!!!!!!!!!!!
      

  10.   

    这问题我解决了,还是看的资料,未懂之前我完全用的javascript,浪费了很多代码,http://www.myexception.cn/web/871383.html