Javascript J-Query初学者-关于JQuery Paypal购物车的问题
我正在使用下面的脚本在我的html页面上添加Paypal购物车Javascript J-Query初学者-关于JQuery Paypal购物车的问题,javascript,jquery,html,Javascript,Jquery,Html,我正在使用下面的脚本在我的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> <scri
<!-- 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页面上的我的项目显示为
<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>
将项目添加到我的购物车
谢谢你抽出时间我真的很感谢你的帮助
当我使用谷歌浏览器运行控制台检查页面上的错误时,这里是我得到的错误
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”函数时使用这些属性
添加到“立即购买”链接:
然后添加此代码以注册“立即购买”链接的单击处理程序:
$(文档).ready(函数(){
$('.buyNow')。单击(函数(事件){
event.preventDefault();
var$link=$(此);
$(“#myCart”).PayPalCart('add',
$link.attr('data-code'),
$link.attr('data-description'),
$link.attr('data-quantity'),
$link.attr('data-value'),
$link.attr(“数据增值税”);
});
});
通过这种方式,您可以为不同的项目提供多个“立即购买”链接,并且此单击处理程序将适用于所有项目。如果您愿意,您可以将此代码放在您已有的
元素中。Paypal的文档在哪里?我只对使用JQ命令将项目添加到购物车中感兴趣,其他一切都很好。非常感谢您,让我尝试一下,我会回复您,让您知道发生了什么。单击“无任何事情发生”:(@Loading-您是否像我在回答中所显示的那样将“buyNow”类添加到
元素?这就是我选择链接注册点击处理程序的方式。除了注册点击处理程序,您还应该从这个回答中获得三件事:(1)使用类来标识元素,(2)在单击处理程序中使用this
和data-
属性,使单击处理程序可用于多个元素,以及(3)调用event.preventDefault()
在
元素的单击处理程序中,这样浏览器就不会导航到href
属性的值。我很肯定你是对的,我对jQuery完全陌生,所以任何短语都需要我花很多时间来研究。请给我一些时间,根据你的评论来解决这个问题,我会告诉你什么我得到了…再次感谢你在这件事上陪在我身边我很遗憾地告诉你我还是做不到:(这是我索引文件的链接按钮在635行
$("myCart").PayPalCart('add', code, description, quantity, value, vat);
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
<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>