使用PHP变量创建弹出窗口

时间:2022-11-20 10:42:34

I am trying to a create a pop-up for product but I Am not even able to see the object in alert box: I have defined $new_date = date('m-d-Y', $dt); in another Div

我正在尝试为产品创建一个弹出窗口,但我甚至无法在警告框中看到该对象:我已定义$ new_date = date('m-d-Y',$ dt);在另一个分区

Code:

<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('this.$new_date' );
                //tried alert(".$new_date.");
            }
        });
    })
    </script>

Also I want to create a pop-up instead of alert:

另外我想创建一个弹出窗口而不是警告:

<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')){
             <class="productcart" data-toggle="modal" data-target="#myModal_product">Open Modal</button>

  <!-- 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>
        }
    });
})
</script>

Something like this But I don't get error in console nor it works...

像这样的东西但我没有在控制台得到错误也没有工作......

Actual .tpl file

实际的.tpl文件

            <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('this <?php echo $new_date?>' );
                }
            });
        })
        </script>

    <div class="thumbnails grid row list-inline">
        <?php
        $icount = 0;
        foreach ($products as $product) {
            $item = array();
            $item['image'] = $product['thumb']['thumb_html'];
            $item['title'] = $product['name'];
            $item['description'] = $product['model'];
            $item['rating'] = ($product['rating']) ? "<img src='" . $this->templateResource('/image/stars_' . $product['rating'] . '.png') . "' alt='" . $product['stars'] . "' />" : '';

            $item['info_url'] = $product['href'];
            $item['buy_url'] = $product['add'];

            $preSaleImg = '';
            $expectedShippingDate = '';
            $newPriceClass = '';
            $preSaleClass = '';
            if($product['date_available'] > date('Y-m-d')){
                $preSaleImg = "<img src='" . $this->templateResource('/image/pre-sale.png') . "' class='pre-sale-img'>";
                $dt = strtotime($product['date_available']); 
                $new_date = date('m-d-Y', $dt);
                $expectedShippingDate = "<span class='expected-shipping-date'>expected shipping date " . $new_date . "    </span>";
                $newPriceClass = "price-with-expected-shipping-date";
                $preSaleClass = 'pre-sale-product';
            }
            if (!$display_price) {
                $item['price'] = '';
            }

            $review = $button_write;
            if ($item['rating']) {
                $review = $item['rating'];
            }
            if($icount == 4) {
                $icount = 0;
        ?>
                <div class="clearfix"></div>
        <?php
            }
            $icount++;
        ?>
            <div class="col-md-3 col-sm-6 col-xs-6">
                <div class="fixed_wrapper">
                    <div class="fixed">
                        <a class="prdocutname" href="<?php echo $item['info_url'] ?>"
                           title="<?php echo $item['title'] ?>"><?php echo $item['title'] ?></a>
                        <?php echo $this->getHookvar('product_listing_name_'.$product['product_id']);?>
                    </div>
                </div>
                <div class="thumbnail">
                    <?php if ($product['special']) { ?>
                        <span class="sale tooltip-test"><?php echo $text_sale_label; ?></span>
                    <?php } ?>
                    <?php if ($product['new_product']) { ?>
                        <span class="new tooltip-test"><?php echo $text_new_label; ?></span>
                    <?php } ?>
                    <?php echo $preSaleImg; ?>
                    <a href="<?php echo $item['info_url'] ?>"><?php echo $item['image'] ?></a>


                    <div class="blurb"><?php echo $product['blurb'] ?></div>
                    <?php echo $this->getHookvar('product_listing_details0_'.$product['product_id']);?>
                    <?php if ($display_price) { ?>
                        <div class="pricetag jumbotron">
                            <span class="spiral"></span>
                            <?php if($product['call_to_order']){ ?>
                                <a data-id="<?php echo $product['product_id'] ?>" href="#"
                                       class="btn call_to_order"><?php echo $text_call_to_order?>&nbsp;&nbsp;<i class="fa fa-phone"></i></a>
                            <?php } else if ($product['track_stock'] && !$product['in_stock']) { ?>
                                <span class="nostock"><?php echo $product['no_stock_text']; ?></span>
                            <?php } else { ?>
                                <a data-id="<?php echo $product['product_id'] ?>"
                                                           href="<?php echo $item['buy_url'] ?>"
                                                           class="productcart <?php echo $preSaleClass; ?>"><?php echo $button_add_to_cart ?></a>
                            <?php } ?>
                            <div class="price">
                                <?php if ($product['special']) { ?>
                                    <div class="pricenew"><?php echo $product['special'] ?></div>
                                    <div class="priceold"><?php echo $product['price'] ?></div>
                                <?php } else { ?>
                                    <div class="oneprice <?php echo $newPriceClass; ?>"><?php echo $expectedShippingDate; ?><span class='aslowas' style="font-size:12px;">AS LOW AS: </span><?php echo $product['price'] ?></div>
                                <?php } ?>
                            </div>
                            <?php echo $this->getHookvar('product_listing_details1_'.$product['product_id']);?>
                        </div>
                    <?php } ?>
                </div>
            </div>
        <?php
        }
        ?>
    </div>

<div class="thumbnails list row">
    <?php
    foreach ($products as $product) {
        $item = array();
        $item['image'] = $product['thumb']['thumb_html'];
        $item['title'] = $product['name'];
        $item['rating'] = ($product['rating']) ? "<img src='" . $this->templateResource('/image/stars_' . $product['rating'] . '.png') . "' alt='" . $product['stars'] . "' />" : '';

        $item['info_url'] = $product['href'];
        $item['buy_url'] = $product['add'];
        if (!$display_price) {
            $item['price'] = '';
        }

        $review = $button_write;
        if ($item['rating']) {
            $review = $item['rating'];
        }

        ?>
        <div>
            <div class="thumbnail">
                <div class="row">
                    <div class="col-md-4">
                        <?php if ($product['special']) { ?>
                            <span class="sale tooltip-test"><?php echo $text_sale_label; ?></span>
                        <?php } ?>
                        <?php if ($product['new_product']) { ?>
                            <span class="new tooltip-test"><?php echo $text_new_label; ?></span>
                        <?php } ?>
                        <?php echo $this->getHookvar('product_listing_label_'.$product['product_id']);?>
                        <a href="<?php echo $item['info_url'] ?>"><?php echo $item['image'] ?></a>
                    </div>
                    <div class="col-md-8">
                        <a class="prdocutname" href="<?php echo $item['info_url'] ?>"><?php echo $item['title'] ?>
                            <?php echo $product['model'] ? "(".$product['model'].")" :''; ?></a>
                        <div class="productdiscrption"><?php echo $product['description'] ?></div>

                        <div class="blurb"><?php echo $product['blurb'] ?></div>
                        <?php echo $this->getHookvar('product_listing_details00_'.$product['product_id']);?>
                        <?php if ($display_price) { ?>
                        <div class="pricetag pull-right">
                            <span class="spiral"></span>

                            <?php if($product['call_to_order']){ ?>
                                <a data-id="<?php echo $product['product_id'] ?>" href="#"
                                       class="btn call_to_order"><?php echo $text_call_to_order?>&nbsp;&nbsp;<i class="fa fa-phone"></i></a>
                            <?php } else if ($product['track_stock'] && !$product['in_stock']) { ?>
                                <span class="nostock"><?php echo $product['no_stock_text']; ?></span>
                            <?php } else { ?>
                                <a data-id="<?php echo $product['product_id'] ?>"
                                                           href="<?php echo $item['buy_url'] ?>"
                                                           class="productcart"><?php echo $button_add_to_cart ?></a>
                            <?php } ?>


                            <div class="price">
                                <?php if ($product['special']) { ?>
                                    <div class="pricenew"><?php echo $product['special'] ?></div>
                                    <div class="priceold"><?php echo $product['price'] ?></div>
                                <?php } else { ?>
                                    <div class="oneprice"><?php echo $product['price'] ?></div>
                                <?php } ?>
                            </div>
                        </div>
                        <?php } ?>
                        <?php echo $this->getHookvar('product_listing_details11_'.$product['product_id']);?>
                    </div>

                </div>
            </div>
        </div>
    <?php
    }
    ?>
</div>

Code for modal at the bottom of .tpl file

.tpl文件底部的模态代码

 <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')){
             <class="productcart" data-toggle="modal" data-target="#myModal_product">Open Modal</button>

  <!-- 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>
        }
    });
})
</script>

1 个解决方案

#1


0  

I think $new_date is a PHP variable, right? If it's true, you have to echo it out using PHP. Try this:

我认为$ new_date是一个PHP变量,对吧?如果是真的,你必须使用PHP来回应它。试试这个:

alert('this <?php echo $new_date?>' );

#1


0  

I think $new_date is a PHP variable, right? If it's true, you have to echo it out using PHP. Try this:

我认为$ new_date是一个PHP变量,对吧?如果是真的,你必须使用PHP来回应它。试试这个:

alert('this <?php echo $new_date?>' );