单击

时间:2016-03-05 11:28:50

标签: javascript php jquery html

你好任何人都可以帮助我,我不能隐藏while循环中的第二个或任何其他按钮,只要textbox的值小于5,那么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   } ?>

2 个答案:

答案 0 :(得分:0)

更改element.value&gt; '5'到element.value&gt; 5

答案 1 :(得分:0)

您为每个<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 ')

   }    
}