我做了一个代码,在该代码中,当用户键入数量he.she想要的产品时,我试图添加产品的数量。问题是我不能通过jquery选择anchor
以获得href
链接,以便我可以为其添加新值。获取href链接并通过jQuery向其中添加值
我的代码:
$('.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
链接。
我看到了'cart'类中没有的元素。 – 2013-03-19 09:26:56
我将类名更改为容器。我把它改回 – user1001176 2013-03-19 09:31:51