$(window.parent.document).find('input[name=address_id]').each(function(){
     $(this).attr('onclick', 'javascript:yinCang(this);');
 });这段代码是给父级页面的多个radio元素添加onclick事件,此段代码在IE下,正常运行,但在ff下可以。
请大侠帮忙看看!该怎么写才能正常兼容.

解决方案 »

  1.   

    $(this).bind('onclick', 'javascript:yinCang(this);');
      

  2.   

    $(window.parent.document).find('input[name=address_id]').click(yinCang);
      

  3.   

    $(window.parent.document).find('input[name=address_id]').bind("click",function(){
    var evt=arguments.caller[0],$this=evt.srcElement;
    });
      

  4.   

    $(window.parent.document).find('input[name=address_id]').click(function(){
      yinCang(this);
    });
      

  5.   


    $("input[name='address_id']", parent.document).click(function(){
          yinCang(this);
    });
      

  6.   

    注意,是多个radio,都要绑定这个方法
      

  7.   

    选择器选的就是多个的, 不需要用each分别处理,除非每个处理函数不同
      

  8.   

    主页面:parentPage.htm<!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></title>
    </head>
    <body>
        <input name="address_id" type="radio" value="A" />A<br />
        <input name="address_id" type="radio" value="B" />B<br />
        <input name="address_id" type="radio" value="C" />C<br />
        <input name="address_id" type="radio" value="D" />D<br />
        <iframe width="200px" height="100px" src="subPage.htm" ></iframe>
    </body>
    </html>子页面: subPage.htm<!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></title>
        <script src="jquery/jquery-1.3.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
                $(window.parent.document).find('input[name=address_id]').click(function () {
                    yinCang(this);
                });
            });
            function yinCang(obj) {
                alert(obj.value);
            }
        </script>
    </head>
    <body>
        <div style="width:100px;height:100px;background:red;"></div>
    </body>
    </html>
    我已测试通过, IE/Firefox/Chrome 三种浏览器都没有问题。 
    你可以试一下, 记得把jquery路径改一下就好了。