在javascript中单击另一个按钮后激活按钮

activate button after another button click in javascript

本文关键字:按钮 激活 另一个 单击 javascript      更新时间:2023-09-26

我有三个按钮,点击一个按钮后,第二个必须访问点击,然后是第三个。当我点击第三个按钮时,它不应该工作

<input type="button" value="button" id="one" onclick="show()" action="">
<input type="button" value="button" id="two" onclick="show1()">
<input type="action" value="button" id="three">
<script>
function show{ 
}
</script>

首先禁用第二个和第三个按钮,使用:

<input type="button" value="button" id="two" onclick="show1()" disabled="disabled"/>
<input type="action" value="button" id="three" disabled="disabled"/>

并使用以下代码:

function show()
{
    document.getElementById('two').removeAttribute('disabled');
}
// And Same For Second Button Click
function show1()
{
    document.getElementById('three').removeAttribute('disabled');
}

jQuery在这里会更好:

$('#one').click(function () { // on a click on the button with id 'one'
  $('#two').trigger('click');// trigger the click on second, and go on 
}

使用此方法,您可以使用特定元素上的事件触发其他元素上的事件!

    <script>
    function show(){ 
$('#button1').attr('disabled',false);
$('#button2').attr('disabled',false);
    }
    function show1(){
$('#button2').attr('disabled',false);
    }
    </script>

你在找这个吗

$("input").click(function(){
 $("input").attr('disabled','disabled');
$(this).next().removeAttr('disabled');
});

你可以使用Jquery绑定一个事件到点击。在那里做你想做的:

$('#ButtonID').bind('click',function(){
   $('#ButtonID2').show(); 
    //or
   $('#ButtonID1').removeAttr('disabled');//if you want it be shown but not enabled
});

这是用来禁用按钮的:

 $('#ButtonID').attr('disabled','disabled');