您好,有人可以帮助我在文本框的值小于5时无法在while循环中隐藏第二个或任何其他按钮的情况,然后btn_cart的按钮应该禁用bt,这是没有发生的,只能禁用第一个按钮在while循环中,如果我将任何其他文本框的值更改为小于5 bt,则我的第一个按钮被禁用而不是其他按钮。请帮助我固定住
function toggle(element) {
if (element.value>'5') {
document.getElementById('btn_cart').style.visibility='visible';
}
else {
document.getElementById('btn_cart').style.visibility='hidden';
alert('Please have Minimum 5 Quantity ')
}
}
<?php include ('dbconnect.php');
$prodetails = mysql_query("Select * from product where category_id='$product_id' ORDER BY product_craetedate DESC ");
while ($fetchprodata = mysql_fetch_array($prodetails))
{
?>
<input type="number" class="item_quantity" value="5" id="" onChange="toggle(this)" />
<?php echo "<input type='button' class='item_add items' name='btn_cart' id='btn_cart' value='ADD'>" ?>
<?php } ?>
您已为每个用户指定了相同的ID,<input type="button".......>
因此在执行操作时document.getElementById('btn_cart').style.visibility='visible';
,它将仅隐藏第一个按钮。
<?php include ('dbconnect.php');
$prodetails = mysql_query("Select * from product where category_id='$product_id' ORDER BY product_craetedate DESC ");
$i = 1
while ($fetchprodata = mysql_fetch_array($prodetails))
{
?>
<input type="number" class="item_quantity" value="5" id="<?php echo $i?>" onChange="toggle(this)" />
<?php echo "<input type='button' class='item_add items' name='btn_cart' id='btn_cart".$i."' value='ADD'>" ?>
<?php
$i++;
} ?>
脚本更改
function toggle(element) {
if (element.value<'5') {
document.getElementById('btn_cart'+element.id).style.visibility='hidden';
alert('Please have Minimum 5 Quantity ')
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句