单击时无法禁用第二个按钮或任何其他按钮


Not able to disable the second button or any other button when clicking on

你好,任何人都可以帮我,我无法在 while 循环中隐藏第二个或任何其他按钮,只要文本框的值小于 5,那么btn_cart的按钮应该被禁用 bt 它没有发生,如果我将任何其他文本框的值更改为小于 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   } ?>

您为每个<input type="button".......>都提供了相同的 id 所以当你做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 ')
   }    
}

将 element.value> '5' 更改为 element.value> 5

相关文章: