将警报消息转换为弹出窗口

时间:2016-09-20 15:58:20

标签: javascript php jquery html

我可以在用户点击一组特定产品时创建警告消息,但如何显示弹出窗口而不是警告消息 代码:

<script>
        $(document).ready(function(){
            $('.pre-sale-product').on('click', function(){
                $('.productcart').addClass('pre-sale-item-included');
            });
            $('.productcart').on('click', function(){
                if($(this).hasClass('pre-sale-item-included')){
                    alert('will ship on <?php echo $new_date?>. Do you agree?');
                }
            });
        })
 </script>
        <!-- Modal -->
      <div class="modal fade" id="myModal_product" role="dialog">
        <div class="modal-dialog">

          <!-- Modal content-->
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              <h4 class="modal-title">Modal Header</h4>
            </div>
            <div class="modal-body">
              <p>Some text in the modal.</p>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
          </div>

        </div>
      </div>

我希望这个弹出窗口而不是警报,选项说“勾选是”作为复选框,它会进一步移动

3 个答案:

答案 0 :(得分:1)

您只需使用$('#myModal_product').modal('show');

即可

试试这个:

&#13;
&#13;
$(document).ready(function() {
  $('.pre-sale-product').on('click', function() {
    $('.productcart').addClass('pre-sale-item-included');
  });
  $('.productcart').on('click', function() {
    if ($(this).hasClass('pre-sale-item-included')) {
      $('#myModal_product').modal('show');
    }
  });
})
&#13;
.pre-sale-item-included {
  border-color: red;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Modal -->
<div class="modal fade" id="myModal_product" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <p>Will ship on <?php echo $new_date?>. Do you agree?</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-success btn-default" data-dismiss="modal">Yes</button>
        <button type="button" class="btn btn-danger btn-default" data-dismiss="modal">No</button>
      </div>
    </div>
  </div>
</div>

<input type="button" class="pre-sale-product" value="pre-sale-product" />
<input type="button" class="productcart" value="productcart" />
&#13;
&#13;
&#13;

答案 1 :(得分:0)

<script> $(document).ready(function(){ $('.pre-sale-product').on('click', function(){ $('.productcart').addClass('pre-sale-item-included'); }); $('.productcart').on('click', function(){ if($(this).hasClass('pre-sale-item-included')){ $('#myModal_product').modal('show'); } }); }) </script> 添加到您的脚本而不是警报。并在模态中添加您的消息

{{1}}

答案 2 :(得分:0)

如果你想打开一个模态...试试这个

$( '#myModal_product')模态( '显示');