我有一个jQuery脚本,它将抓取一些html,并在每次单击“添加产品”时重复该脚本。我看起来很好,但我意识到可以添加多个产品(同一产品)。因此,单选按钮会发生干扰。他们需要独特的广播名称属性。我甚至不知道从哪里开始做这件事,我想我可以有一个计数器,并将其添加到当前的名称......预先感谢任何帮助。为单选按钮添加唯一名称
下面是HTML的例子:
<div id="product-container" class="product-container" style="display:none">
<div class="product-wrapper white-rounded">
<div id="product-name" style="display:none"></div>
<h4>Example Product 1</h4>
<span class="align-right">
<input name="select2" type="radio"><strong style="margin-right:20px">Option 1</strong>
<input name="select2" type="radio"><strong>Option 2</strong>
</span>
<div class="remove float-right">
<a href="#"><div class="img-remove"></div>Remove</a>
</div>
<div class="clear"></div>
</div>
</div>
而且,这里是抓住代码并吐出它在一个锚点jQuery的:
$('.add-product').click(function() {
if (Products < 4 || (Products == 4 && Products2 == 1)) {
//Store html contents in Variable
var thisProduct = $('#product-container').html()
//Add account html to account center anchor point
$('.add-product').before(thisProduct)
$('#product-name').text(productName)
//Add one more Product Count
Products++
//Add Product Count value to hidden Input Field, then manually trigger the change event.
$('.product-count').val(Products).change()
//Scroll to top of page after account is added
$('html, body').animate({scrollTop:0}, 'slow');
}
else {
alert('HALP!');
}
});
它看起来像你的代码是重复的ID,以及与这一个不 - 不。 – j08691 2012-07-25 17:12:56
好吧,它使用ID抓取容器内的html,并且不会在实际标记中重复它。至少我不这么认为......但我会仔细检查。谢谢。 – TurboSupra 2012-07-25 17:14:50