有没有人可以帮助我如何根据单击事件启用按钮。
我需要一个场景,其中我们有两个按钮,Button1和Button2(默认情况下禁用)。
单击Button1后,假设10秒后应启用my Button2。
在下面的代码中,我哪里做错了?单击Button1后,我的Button2未启用。有人能帮我吗。
提前谢谢你,乌代
<html>
<Head>
<Title>Synchronization</Title>
</head>
<script>
function PleaseWait()
{
document.getElementsByName("SampleButton2").disabled=false;
}
</script>
<body>
<input type="button" name="SampleButton1" value="Button1" onclick="PleaseWait()">
<input type="button" name="SampleButton2" value="Button2" disabled>
</body>
</html>发布于 2014-04-30 18:16:39
你可以用jQuery做到这一点。
在$(document).ready()方法中,定义一个函数PleaseWait(),您可以在其中编写代码来删除按钮中的禁用属性。
然后,当任何用户单击button1时,使用setTimeout()方法触发一个函数在一段延迟后调用pleaseWait()函数。我使用了5毫秒作为延迟。您可以增加或减少它。
<!DOCTYPE html>
<html>
<head>
<title>DOM Level 0 Events Example</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
<input type="button" name="SampleButton1" value="Button1">
<input type="button" name="SampleButton2" value="Button2" disabled>
<script type="text/javascript">
$(document).ready(function(e){
function PleaseWait(){
$('input[value="Button2"]').removeAttr('disabled');
}
$('input[value="Button1"]').click(function(e) {
setTimeout(PleaseWait, 5000);
});
});
</script>
</body>
</html>发布于 2014-04-30 18:12:05
尝尝这个
document.getElementsByName("SampleButton2").removeAttr('disabled');或者您可以使用
$('SampleButton2').prop('disabled', false);https://stackoverflow.com/questions/23385045
复制相似问题