doukai2839
2017-02-22 00:50
浏览 43
已采纳

带有复选框的Bootstrap模式,以便将来不显示

I am trying to show a bootstrap modal on body load based on value from mysql database. I have included bootstrap modal in body and showing it successfully according to database value with:

    $resultsPop = mysql_query("select popup from members where mid=" . $mid);
    $pop = mysql_result($resultsPop, 0, "popup");
    if($pop == 0) {
            $popupval = "<script type='text/javascript'>$(window).load(function(){ $('#MyPopUp').modal('show'); });</script>";
    } else {
            $popupval = "";
    }
echo $popupval;

And my modal code is:

  <div class="modal fade" id="MyPopUp" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">Welcome</h4>
            </div>

                <div class="modal-body" style="text-align: center;">
                   <span>
                        Welcome Popup
                  </span>
                </div>
        </div>
    </div>
</div>

Now, I want to have a checkbox in the modal which on checked can silently pass value 1 and logged in member variable $mid value to a php page after user clicks on modal close button. So, popup value in members table is updated with 1 for that logged in member who do not want popup to be see again.

I have searched for such thing but couldn't successful and I am getting no idea on it.

图片转代码服务由CSDN问答提供 功能建议

我试图根据mysql数据库中的值显示主体加载的bootstrap模式。 我已经在body中包含了bootstrap模式,并根据数据库值成功显示:

  $ resultsPop = mysql_query(“select member from mid =”。$ mid);  
 $ pop = mysql_result($ resultsPop,0,“popup”); 
 if($ pop == 0){
 $ popupval =“&lt; script type ='text / javascript'&gt; $(window)  .load(function(){$('#MyPopUp')。modal('show');});&lt; / script&gt;“; 
} else {
 $ popupval =”“; 
} 
echo  $ popupval; 
   
 
 

我的模态代码是:

 &lt; div class =“modal fade”id  =“MyPopUp”tabindex =“ -  1”role =“dialog”aria-labelledby =“myModalLabel”aria-hidden =“true”style =“”&gt; 
&lt; div class =“modal-dialog modal-lg”  &gt; 
&lt; div class =“modal-content”style =“”&gt; 
&lt; div class =“modal-header”&gt; 
&lt; button type =“button”class =“close”data  -dismiss =“modal”aria-label =“Close”&gt; 
&lt; span aria-hidden =“true”&gt;&amp; times;&  lt; / span&gt;&lt; / button&gt; 
&lt; h4 class =“modal-title”id =“myModalLabel”&gt;欢迎&lt; / h4&gt; 
&lt; / div&gt; 
 
&lt; div class =  “modal-body”style =“text-align:center;”&gt; 
&lt; span&gt; 
欢迎Popup 
&lt; / span&gt; 
&lt; / div&gt; 
&lt; / div&gt; 
  &lt; / div&gt; 
&lt; / div&gt; 
   
 
 

现在,我希望在模式中有一个复选框,在选中时可以静默传递值 1 并在用户单击模态关闭按钮后将成员变量 $ mid 值登录到php页面。 因此, members 表中的 popup 值将使用 1 更新,该成员不希望再次看到弹出窗口。

我搜索过这样的东西但是没有成功,我不知道它。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doubiaokai4998 2017-02-22 01:37
    已采纳

    Try this.

    yourphpfile.php

    <?php
    
    $resultsPop = mysql_query("select popup from members where mid=" . $mid);
        $pop = mysql_result($resultsPop, 0, "popup");
        if($pop == 0) {
                $popupval = "<script type='text/javascript'>$(window).load(function(){ $('#MyPopUp').modal('show'); });</script>";
        } else {
                $popupval = "";
        }
    echo $popupval;
    
    $ppop = $_POST['pops'];
    $username = $_POST['mids'];
    
    //Here you can update your database with 1 where username is mids.
    
    //On success 
    $output = json_encode(array('type' => 'pop'));
    die($output);
    
    //Else
    
    $output = json_encode(array('type' => 'error'));
    die($output);
    
    ?>

    <script>
    
    $(document).ready(function(){
    
    $("#closemodal").click(function(event){
        event.preventDefault();
        var popups            = $('#popups').val(); 
        var user_id           = $('#mids').val();
     
            $.ajax({
                type: 'post',
                url: yourphpfile.php,
                dataType: 'json',
                data: $('#yourform').serialize(),             
                success: function(data)
                {
                    if(data.type == 'pop')
                    {
                        $('#MyPopUp').modal('hide');                  
                      
                    }
                }
            });
    
    });
    
    });
    
    </script>

    <div class="modal fade" id="MyPopUp" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="">
        <div class="modal-dialog modal-lg">
            <div class="modal-content" style="">
                <div class="modal-header">
                    <button type="button" class="close" id="closemodal" aria-label="Close">
                                            <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">Welcome</h4>
                </div>
    
                    <div class="modal-body" style="text-align: center;">
                       <span>
                            Welcome Popup
                      </span>
                      <form action="" id="yourform" method="POST" role="form">                    
                      
                        <div class="checkbox">
                          <label><input type="checkbox" name="pops" id="popups" value="1">Pops</label>
                        </div>
                        <input type="hidden" id="mids" name="mids" value="<?php echo $_SESSION['mids']; ?>">                  
                      </form>
                    </div>
            </div>
        </div>
    </div>

    </div>
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题