jQuery,.html,添加一个div元素
我正在尝试添加一个包含折扣优惠券一些详细信息的 div,以便用户可以在将其添加到购物车之前进行确认。
按钮等的代码是这样的,如果我放在网站上它就可以工作:
<div class="simpleCart_shelfItem"><h1 class="item_name">Discount of 30%!</h1><a href="javascript:;" class="item_add">Confirm Coupon!</a><span class="item_price" >0.00€</span></div>
然后,我尝试使用 jQuery 动态添加代码(当 php 帖子确认优惠券代码没问题时),但是通过一些奇怪的原因它不起作用。
我设法这样写:
$('div.cupao_confirm').html('<div class="simpleCart_shelfItem"><h1 class="item_name">Discount of 30%!</h1><a href="javascript:;" class="item_add">Confirm Coupon!</a><span class="item_price" >0.00€</span></div>');
如果没有 jQuery,代码会将“0.00€”产品添加到购物车中,这样我以后就可以将等值的钱退给买家。使用 jQuery,当我点击链接时什么也没有发生。所以这不是 jQuery 相关的问题...我可能做错了 .html()...:( 帮助!
谢谢!
I'm trying to add a div with some details of a discount coupon so the user can confirm it before I add it to the shopping cart.
The code to the button etc... is this, and it works if I place on the website:
<div class="simpleCart_shelfItem"><h1 class="item_name">Discount of 30%!</h1><a href="javascript:;" class="item_add">Confirm Coupon!</a><span class="item_price" >0.00€</span></div>
Then, I tried to dynamically add the code (when a php post confirms that the coupon code is OK) using jQuery, but by some strange reason it doesn't work.
I managed to write this:
$('div.cupao_confirm').html('<div class="simpleCart_shelfItem"><h1 class="item_name">Discount of 30%!</h1><a href="javascript:;" class="item_add">Confirm Coupon!</a><span class="item_price" >0.00€</span></div>');
Without jQuery the code add the "0.00€" product to the shopping cart, so I can later send the equivalent money back to the buyer. With jQuery when I click on the link nothing happens at all. So it's not a jQuery related problem... I might be doing the .html() wrong... :( help!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
append()
方法:尝试一下,让我知道它是否有效,谢谢。
try to use the
append()
method :Give it a try and let me know if it worked, Thanks.
我想也许你需要重新初始化简单的购物车更改外壳内容。尝试:
I think maybe you need to re-initialize simple cart ager changing the shell contents. Try: