我制作了一个代码,当用户输入他想要的产品数量时,我试图在其中添加产品的数量。问题是我无法选择anchor
通过 jquery 来获取href
链接,以便我可以为其添加新值。
我的代码:
$('.mival').keyup(function(event) {
var i=$(this).parents(".cart").next('.milink').attr('href');
alert(i);
});
当我试图提醒它说undefined
我的 html 标记:
<div class="cart">
<div><strong>Price:</strong> <span>$20.30</span></div>
<div><strong> Qty:</strong><span>
<input type="text" class="mival" value="1" />
</span></div>
<a class="milink" href="http://example.com/vid=3">Add to Cart </a> </div>
我还没有编写将值添加到我可以做到的链接的代码。问题是如何从这个标记的a
元素中获取价值,以便我可以获得href
链接。