【问题标题】:Syntax for changing FancyBox close button into submit button将 FancyBox 关闭按钮更改为提交按钮的语法
【发布时间】:2014-06-18 07:16:35
【问题描述】:

向 FancyBox 的 FancyApps2 close 按钮添加帮助函数以将其变为 submit 按钮的语法是什么?

我需要添加以下内容:

input type="submit" 
name="whereto" 
value="" 

当前 FancyBox 函数

$(function () {
  $(".fancybox_iframe").fancybox({
    type: 'iframe',
    padding: 0,
    scrolling: 'no',
    width: 840,
    minHeight: 150,
    height: 615,
    closeBtn: true,
    helpers: { overlay: { closeClick: false, opacity: .5} },
    afterShow: function () { $("a.fancybox-close").attr("title", null); },
    afterClose: function () {
        parent.close_field('notice');
        parent.closeiframe_redirect('index.php');
    }
  });
});

【问题讨论】:

    标签: javascript jquery fancybox-2 submit-button


    【解决方案1】:

    你可以使用它的afterShow方法:

    afterShow: function () { 
       var input = $('<input />', {
           type : "submit",
           name : "whereto",
           value : ""
       });
       $("a.fancybox-close").replaceWith(input); 
    },
    

    【讨论】:

    • afterShow 是回调,而不是方法;)
    【解决方案2】:

    可以使用隐藏的提交按钮和jquery的触发方法吗?

    http://jsfiddle.net/B6KE6/

    <a class="fancybox" href="http://fancyapps.com/fancybox/demo/1_b.jpg">
        <img src="http://fancyapps.com/fancybox/demo/1_s.jpg" alt=""/>
    </a>
    
    <form style='display: none;' action='#?hey-it-works' method='get'>
        <input type='submit' class='fancysubmit' name='whereto' value='' />
    </form>
    
    <script type='text/javascript'>
    $(document).ready(function() {
        $(".fancybox").fancybox({
            padding: 0,
            scrolling: 'no',
            width: 840,
            minHeight: 150,
            height: 615,
            closeBtn: true,
            helpers: { overlay: { closeClick: false, opacity: 0.5} },
            afterShow: function () { $("a.fancybox-close").attr("title", null); },
            afterClose : function() {
                $(".fancysubmit").trigger('click');
                return;
            }
        });
    });
    </script>
    

    【讨论】:

      【解决方案3】:

      在其他地方创建一个提交按钮,然后在 afterClose 上使用 jQuery trigger 触发按钮。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-05-22
        • 2012-09-15
        • 1970-01-01
        • 1970-01-01
        • 2014-08-17
        • 2018-10-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多