簡體   English   中英

時間間隔后如何禁用單選按鈕

[英]How to disable radio button after a time interval

這是我的PHP腳本功能

$xRadio = 0;<br>
echo"<script type='text/javascript' src='http://code.jquery.com/jquery-2.0.2.min.js'><br>   </script>";
echo"<script type='text/javascript'> 
 $xRadio = setInterval(function(){ $('.radio').attr('disabled',true);},3000);
</script>";

這是我想在PHP中禁用的單選按鈕

echo "<td><input type='radio' class='radio' name='$i' value='A'>" . $row['opt_a'] . "</td>";

使用setTimeout() ,您只需調用一次函數。 將其包裝在$(document).ready()函數中,因為在運行此腳本時我不確定DOM是否准備就緒。 使用jQuery的prop()而不是attr()

$(document).ready(function(){
    $xRadio = setTimeout(function(){
        $('.radio').prop('disabled',true);
    }, 3000);
});

對不起,如果我也沒有添加您的PHP,但這與問題無關。

只需嘗試修改后的代碼即可。

 echo "<td><input type='radio' class='radio' name='$i' value='A'>" . $row['opt_a'] . "</td>";
    $xRadio = 0;echo "<br>";

    echo"<script type='text/javascript' src='http://code.jquery.com/jquery-2.0.2.min.js'><br>   </script>";
    echo"<script type='text/javascript'> 
    setInterval(function(){ $('.radio').attr('disabled',true);},3000);</script>";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM