简体   繁体   English

时间间隔后如何禁用单选按钮

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

Here is my php script function 这是我的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>";

and here is the radio button which i want to disable in php 这是我想在PHP中禁用的单选按钮

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

Use setTimeout() , you only need to call the function once. 使用setTimeout() ,您只需调用一次函数。 Wrap it in a $(document).ready() function, as I'm not sure the DOM is ready when you are running this script. 将其包装在$(document).ready()函数中,因为在运行此脚本时我不确定DOM是否准备就绪。 Use jQuery's prop() instead of attr() 使用jQuery的prop()而不是attr()

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

Excuse me if I don't add your PHP as well, but it is irrelevant for the question. 对不起,如果我也没有添加您的PHP,但这与问题无关。

Just try out this modified code. 只需尝试修改后的代码即可。

 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