dongqu2863 2014-07-30 14:16
浏览 21

如何将JavaScript命令链接到php中的表单按钮? (<DIV>)

I have a footer banner on a website that I manage and when I click hide or hide forever it called the following javascript to hide or hide forever the banner:

/**
 * Main JS File
 *
 * @author Your Inspiration Themes
 * @package YITH Footer Banner
 * @version 1.0.3
 */
jQuery(document).ready(function($) {
    if($.cookie(templateDir) == '1') {
        $(".fbanner").hide();
    }
    $("#showhidefbanner a").on('click',function(event){
        event.preventDefault();
        $('.fbanner').hide();
    });
     $("#showhideforever").on('click',function(event){
        event.preventDefault();
        $(".fbanner").hide();
        $.cookie(templateDir, '1',{ expires: 365, path: '/' });
    });
});

Until here everything ok. The problem is that when someone send the form the banner the banner keeps appearing. Therefore I want to called this javascript to never show this banner again. Here is my php code:

<?php
/**
 * Footer Banner page
 *
 * @author Your Inspiration Themes
 * @package YITH Footer Banner
 * @version 1.0.0
 */
;?>
<!-- YITH-FOOTER-BANNER -->
<div class="fbanner">
    <div id="fbannercont" class="group">
        <div id="fbannerlogo">
            <?php if (get_option('yith_fbanner_link')):?><a href="<?php echo get_option('yith_fbanner_link');?>" title="<?php echo get_option('yith_fbanner_message');?>"><?php endif;?>
                <img src="<?php echo get_option('yith_fbanner_image');?>" alt="<?php echo get_option('yith_fbanner_message');?>"/>
            <?php if (get_option('yith_fbanner_link')):?></a><?php endif;?>
        </div>
        <ul id="fbannermess">
            <li>
                <h3>
                    <?php if (get_option('yith_fbanner_link')):?><a href="<?php echo get_option('yith_fbanner_link');?>" title="<?php echo get_option('yith_fbanner_message');?>"><?php endif;?>
                        <?php echo get_option('yith_fbanner_message');?>
                    <?php if (get_option('yith_fbanner_link')):?></a><?php endif;?>
                </h3>
            </li>
            <li>
                <p>
                    <?php if (get_option('yith_fbanner_link')):?><a href="<?php echo get_option('yith_fbanner_link');?>" title="<?php echo get_option('yith_fbanner_message');?>"><?php endif;?>
                        <?php echo get_option('yith_fbanner_sub_message');?>
                    <?php if (get_option('yith_fbanner_link')):?></a><?php endif;?>
                </p>
            </li>
        </ul>
        <div id="fbannernews">
            <?php if ( get_option('yith_fbanner_enable_newsletter_form') == true ): ?>
                <form method="<?php echo get_option('yith_fbanner_newsletter_method') ?>" action="<?php echo _e (get_option('yith_fbanner_newsletter_action') ,'yit');?>" class="fbannernewsletter">
<input type="hidden" name="form_id" value="147265" />
                <input type="hidden" name="encoding" value="" />                    
<fieldset>
                            <?php if(get_option('yith_fbanner_newsletter_name_label')){?>
                                <ul class="newsfields">
                                    <li class="newstop">
                                        <input type="text" name="<?php echo get_option('yith_fbanner_newsletter_name_name') ?>" id="<?php echo get_option('yith_fbanner_newsletter_name_name') ?>" class="name-field text-field" placeholder="<?php echo get_option('yith_fbanner_newsletter_name_label') ?>" />
                                    </li>
                                    <li class="newsbottom">
                                        <input type="text" name="<?php echo get_option('yith_fbanner_newsletter_email_name') ?>" id="<?php echo get_option('yith_fbanner_newsletter_email_name') ?>" class="email-field text-field" placeholder="<?php echo get_option('yith_fbanner_newsletter_email_label') ?>" />
                                    </li>
                                </ul>
                            <input type="submit" value="<?php echo get_option('yith_fbanner_newsletter_submit_label') ?>" class="submit-field newssubmit" />
                            <?php } else { ?>
                            <input type="text" name="<?php echo get_option('yith_fbanner_newsletter_email_name') ?>" id="<?php echo get_option('yith_fbanner_newsletter_email_name') ?>" class="email-field text-field" placeholder="<?php echo get_option('yith_fbanner_newsletter_email_label') ?>" />
                            <input type="submit" value="<?php echo get_option('yith_fbanner_newsletter_submit_label') ?>" class="submit-field" />
                        <?php };?>
                            <?php $hiddenfields = get_option('yith_fbanner_newsletter_hidden_fields');
                                if ($hiddenfields) :
                                $result = explode('&',$hiddenfields);
                                foreach ($result as $hivalue ) :
                                $formvalue = explode('=',$hivalue);?>
                                    <input type="hidden" id="<?php echo $formvalue[0] ?>" name="<?php echo $formvalue[0] ?>" value="<?php echo $formvalue[1] ?>" />
                                <?php endforeach; endif;?>
                    </fieldset>
                </form>
            <?php endif; ?>
        </div>
    </div><!-- fbannercont -->

    <ul class="hiderzone">
        <li>
            <div id="showhideforever">
                <a href="#" title="<?php _e( get_option('yith_fbanner_hide_forever_message') ,'yit');?>">
                    <?php echo _e( get_option('yith_fbanner_hide_forever_message') ,'yit');?>
                </a>
            </div>
        </li>
        <li>
            <div id="showhidefbanner">
                <a href="#" title="<?php _e( get_option('yith_fbanner_hide_message') ,'yit');?>">
                    <?php _e( get_option('yith_fbanner_hide_message') ,'yit');?>
                </a>
            </div>
        </li>
    </ul>
</div><!-- fbanner -->
<!-- YITH-FOOTER-BANNER -->

Does anyone know how to solve this problem? Thanks in advance

  • 写回答

1条回答 默认 最新

  • dsms21398 2014-07-30 14:39
    关注

    Try to create a js function and call the function after send your form:

    <script>    
    function showHideBannerFix() {
        $(".fbanner").hide();
        $.cookie(templateDir, '1',{ expires: 365, path: '/' });
    }
    </script>
    

    And in your php that the form was submited to:

    echo '<script>showHideBannerFix();</script>';
    

    I didn't test it, but i think its right.

    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据