从父元素获取产品名称 [英] Get product name from parent element
本文介绍了从父元素获取产品名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里我试图在点击立即购买按钮时在警报框中获取产品名称。此外,我需要维护我已经把代码放在jquery中的按钮的onclick事件。
Here I am trying to get the product name in alert box when the "Buy now" button is clicked. Also I need to maintain the onclick event of the button for which I have placed the code in jquery.
<h2 class="product-name"><a href="product1.php" title="Sample Product Name">Sample Product Name</a></h2>
我做的方法是给我一个空白的警告框,可能是因为我在调用父元素。请帮助
The approach that I did is giving me blank alert box might be because I am calling parent element. Please help
请注意,此处我不希望在点击产品名称或图片时发出警报。只需要按钮
Please note that here I don't want the alert when product name or image is clicked. Just want on button
推荐答案
更改此:
Change this:
var text = $(this).parents(".item").find('.product-name').text();
这篇关于从父元素获取产品名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文