• [jQuery] form提交到iframe之后,获取iframe里面内容


    过程不多说,直接上代码

    <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
    var iframe_id_publish = 'works-publish-iframe';
    jQuery(function(){
        jQuery('.works-publish-form').submit(function(){
            var $_this = jQuery(this);
            $_this.attr('action', 'test.php');
    
            //TODO 根据实际情况添加验证规则
            return verify_works_publish_form();
        });
    
        iframe = document.getElementById(iframe_id_publish);
        if (iframe.attachEvent){
        //兼容IE
            iframe.attachEvent("onload", function(){
                iframe_loaded();
            });
        } else {
        // ff, chrome
            iframe.onload = function(){
                iframe_loaded();
            };
        }
    });
    
    function iframe_loaded() {
        //这里就读到form提交到iframe,iframe加载完成之后的页面
        var iframe_obj = jQuery(document.getElementById(iframe_id_publish).contentWindow.document.body);
    }
    
    /**
     * 验证表单 
     * 
     * @access public
     * @return void
     */
    function verify_works_publish_form() {
        return true;
    }
    </script>
    <form class="works-publish-form" target="works-publish-iframe" method="post" action="">
        <input type="text" name="title" value="" />
        <input type="submit" />
    </form>
    <iframe name="works-publish-iframe" id="works-publish-iframe" frameborder="0" width="490" height="92" style="display:none;"></iframe>

    Have fun with jQuery!

  • 相关阅读:
    js模板引擎v5
    js模板引擎v6
    python cookbook学习笔记[一次完成多个字符串的替换]
    您可能没注意到的ie6 select bug
    lambda参数写法问题
    python dict2种遍历方式及区别
    记一次 AXI id debug
    R2B fpga flow script
    axi 1.0
    advanced fpga design
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/3070231.html
Copyright © 2020-2023  润新知