我有一些jquery:
if($('div.ProductNameText').text()=='Product1')
{
$("#kitProduct #Quantity").attr("value", "1");
}
但我想要它,以便如果它找到Product1,那么它允许客户输入超过1。
我正在覆盖之前的jquery,它将其设置为25,因为它会检查它是否为套件产品。
以下是套件产品代码:
function KitOptionsChanged() {
// Get total of selected index... if this is above 0 at least 1 dropdown option has been changed
var totals = 0;
for (var i = 0; i < $('select.selitemoption').length; i++) {
totals += $("select.selitemoption").eq(i).attr("selectedIndex");
}
if (totals == 0) {
// No dropdowns changed from defaults - check textbox
if ($("#kitProduct #KitFormOptions textarea").val() == "") {
// Min value doesn't need to be 25... do i need to anything here?
} else {
//Check current
if (parseInt($("#kitProduct #Quantity").val()) < 25) {
// If it is less than 25 then set it to 25
$("#kitProduct #Quantity").attr("value", "25");
}
if($('div.ProductNameText').text()=='This is product ABC'){
$("#kitProduct #Quantity").attr("value", "1");
}
}
}
else {
// At least 1 index has been changed... set min total to 25.
if (parseInt($("#kitProduct #Quantity").val()) < 25) {
$("#kitProduct #Quantity").attr("value", "25");
}
}
}
编辑:添加数量框html:
<input type="text" maxlength="4" size="3" onkeyup="if(typeof(getShipping) == 'function'){getShipping()}" onchange="if(typeof(getShipping) == 'function'){getShipping()}" id="Quantity" name="Quantity" value="1">
答案 0 :(得分:0)
你可以看到Product1在div中匹配的次数,而count会给你这样的项目数量:
quantity = $('div.ProductNameText').text().match(/Product1/g).length;
if(quantity)
{
$("#kitProduct #Quantity").attr("value", quantity);
}