繁体   English   中英

J-Query初学者-JQuery Paypal购物车出现问题

[英]J-Query Beginner - Issue with JQuery Paypal Shopping Cart

我正在使用以下脚本在我的html页面上添加Paypal购物车

<!-- 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用作结帐付款终端。 Shopping Cart可以完美地工作,但是我找不到如何使我现在购买的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- attribute属性来保存商品的数据,然后在调用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>元素中。

暂无
暂无

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

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