JQuery初学者 - JQuery Paypal购物车问题



我正在使用下面的脚本在我的HTML页面上添加贝宝购物车

<!-- CSS files -->
<link rel="stylesheet" type="text/css" href="js/jPayPalCart.css" />    
<!-- Script files -->
<script src="js/jPayPalCart.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function(){
        // Create a basic cart
        $("#myCart").PayPalCart({ business: 'yourselleremail@yourdomain.com',
            notifyURL: 'http://www.yournotifyURL.com/notify.php',
            virtual: false,             //set to true where you are selling virtual items such as downloads
            quantityupdate: true,       //set to false if you want to disable quantity updates in the cart 
            currency: 'GBP',            //set to your trading currency - see PayPal for valid options
            currencysign: '£',          //set the currency symbol
            minicartid: 'minicart',     //element to show the number of items and net value
            persitdays: 0               //set to -1 for cookie-less cart for single page of products, 
                                        // 0 (default) persits for the session, 
                                        // x (number of days) the basket will persits between visits
            });
    });
</script> 

我面临的问题是:我无法弄清楚如何将以下代码实现到我的HTML项目按钮以将项目添加到购物车

$("myCart").PayPalCart('add', code, description, quantity, value, vat);

我的html页面上的项目显示为

<div class="grid_3">        
    <div class="pricing-table">
        <div class="top">
        <img src="images/p6.jpg" alt=""><br><span class="permonth">"AIMLESS" Gloves</span>
        </div>
        <div class="title">
        $11.95
        </div>
            <ul class="specifications">
                <li>"Aimless" Logo Embroidered Gloves are touch-screen-friendly with conductive thread on the tip of the thumb and fingers.</li>
                <li></li>
                <li></li>
            </ul>
        <p><a class="button" href="#">Buy Now</a></p>
    </div>
</div>

我真的很感谢您在这个问题上的专业知识,这是我第二天在这个问题上。如果有帮助,我遵循此网页上的说明http://www.ultimateweb.co.uk/jpaypalcart/

脚本不是PayPal,这是一个自定义JQ购物车,旨在将PayPal用作结帐付款终端。购物车运行良好,但是我找不到我现在可以购买HTML按钮以将物品添加到购物车中的方式。我从上面提到的脚本下载的网站表示使用此行:

$("myCart").PayPalCart('add', code, description, quantity, value, vat);  

将项目添加到我的购物车

谢谢您的宝贵时间,我非常感谢您的帮助

当我运行控制台以使用Google Chrome检查页面上的错误时,这是我得到的错误

Uncaught ReferenceError: jQuery is not defined custom.js:1
(anonymous function) custom.js:1
Uncaught ReferenceError: jQuery is not defined jPayPalCart.js:223
(anonymous function) jPayPalCart.js:223
Uncaught ReferenceError: $ is not defined index.php:31
(anonymous function) index.php:31
Uncaught ReferenceError: $ is not defined index.php:47
(anonymous function) index.php:47

您需要为"立即购买"链接注册一个点击操作员。您还可以使用data-属性保存项目的数据,然后在调用PayPalcart" add"函数时使用这些属性。

添加到您的"立即购买"链接:

<a class="button buyNow" href="#"
    data-code="theCode"
    data-description="theDescription"
    data-quantity="1"
    data-value="theValue"
    data-vat="theVat">Buy Now</a>

然后添加此代码以注册"立即购买"链接的点击操作员:

<script type="text/javascript">
    $(document).ready(function(){
        $('.buyNow').click(function(event) {
            event.preventDefault();
            var $link = $(this);
            $('#myCart').PayPalCart('add',
                $link.attr('data-code'),
                $link.attr('data-description'),
                $link.attr('data-quantity'),
                $link.attr('data-value'),
                $link.attr('data-vat'));
        });
    });
</script>

这样,您可以拥有多个不同项目的多个"立即购买"链接,并且此点击操作员将对所有物品有效。您可以将此代码放在如果需要的情况下,将此代码放在已经拥有的<script>元素中。

最新更新