简体   繁体   English

JS / JQUERY-单击每个产品购买按钮时显示模式

[英]JS / JQUERY - Show modal when each product buy button is clicked

I have a while statement showing all of my products, like such : https://gyazo.com/68f2ae0dd80e21b6a5f0a7deeb49877f . 我有一阵子的声明显示了我所有的产品,例如: https : //gyazo.com/68f2ae0dd80e21b6a5f0a7deeb49877f I have a javascript / jquery piece of code that when clicked, shows a modal like so : https://gyazo.com/e9b4cf948ec228f221d2526244c2f7bc . 我有一个javascript / jquery代码段,单击后显示的模态如下: https : //gyazo.com/e9b4cf948ec228f221d2526244c2f7bc The problem I'm having is that the modal only shows when I click the Paypal button on the left, first product. 我遇到的问题是,仅当我单击左侧第一个产品上的Paypal按钮时,模态才会显示。 When I click the Paypal button on the right Keyvault product, it does not show the modal eventhough it's a while loop so it should use the same name. 当我单击右侧Keyvault产品上的Paypal按钮时,即使它是while循环,它也不会显示模式,因此应使用相同的名称。

My Modal : 我的模态:

    <div class="modal fade" id="Loading_purchase_status" style="display: none;">
      <div class="modal-dialog modal-lg">
        <div class="modal-content">
          <div class="modal-header">
            <h4 class="modal-title">Payment Status (Don't close this during a payment) <div style="float: right;"><img src="<?php echo $site_config->grabSiteSettings($con, 'site_url').'/pizza/styles/img/loading.gif'; ?>" style="width: 20px; height: 20px;"></div></h4> 
          </div>
          <div class="modal-body">
            <p>Payment Status: <div id="awaiting_payment_status">Awaiting Payment on the Paypal payment page...</div></p>
          </div>
          <div class="modal-footer">
            <a class="btn btn-primary" href="<?php echo $site_config->grabSiteSettings($con, 'site_url').'/pizza/myFiles.php'; ?>">My Files</a>
            <a class="btn btn-danger" data-dismiss="modal">Cancel</a>
          </div>
        </div>
      </div>
    </div>

My Paypal button form : 我的贝宝按钮形式:

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="POST" target="_blank">


    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="<?php
echo $site_config->grabSiteSettings_manual($con, 'paypal_address');
?>">
    <input type="hidden" name="item_name" value="<?php
echo $name;
?>">
    <input type="hidden" name="item_number" value="<?php
echo $id;
?>">
    <input type="hidden" name="amount" value="<?php
echo $price;
?>">
    <input type="hidden" name="quantity" value="1">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="custom" value="username=<?php
echo $username;
?>&product=<?php
echo $name;
?>">
    <input type="hidden" name="notify_url" value="<?php
echo $site_callback;
?>">
    <input type="hidden" name="cancel_return" value="<?php
echo $site_return_canceled;
?>">

    <button type="submit" class="btn btn-danger" id="paypal_submit" aria-hidden="true" data-backdrop="static" data-keyboard="false" style="vertical-align : bottom; margin-bottom: 15px; display: block; width: 40%; float:left; margin-left: 9%;">
        <i class="fa fa-paypal"></i>aypal
    </button>
    <button type="submit" class="btn btn-danger" disabled="true" style="vertical-align : bottom; margin-bottom: 15px; display: block; width: 40%; float: right; margin-right: 9%;">
        <i class="fa fa-btc"></i>itcoin
    </button>
</form>

My Javascript / Jquery : 我的Javascript / Jquery:

        $(document).ready(function() {
        $('#Loading_purchase_status').modal('hide');

        $('#paypal_submit').click(function () {
            $('#Loading_purchase_status').removeData('bs.modal').modal({backdrop: 'static', keyboard: false}); 
            $('#Loading_purchase_status').modal('show');
        });
    });

very basic mistake. 非常基本的错误。 U need to use class name instead of id. 您需要使用类名而不是ID。 as browser changes the id if you have many items with same id rendered through loop. 当您有很多具有相同ID的项目通过循环呈现时,浏览器会更改ID。

so here is the work around 所以这是解决方法

assigne a class name to paypal button eg 将类别名称分配给贝宝按钮,例如

<button class="modalopenerbutton"

and then write the script as follows 然后编写脚本如下

$(document).ready(function() {
        $('#Loading_purchase_status').modal('hide');

        $('.modalopenerbutton').click(function () {
            $('#Loading_purchase_status').removeData('bs.modal').modal({backdrop: 'static', keyboard: false}); 
            $('#Loading_purchase_status').modal('show');
        });
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM