简体   繁体   中英

activate button after another button click in javascript

I have three button are after clicking on one button,second has to access the click and then the third .when i click on the third button it should not work

<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>

Initially disable second and third button using :

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

And Use this code :

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

jQuery would be better here:

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

Using this method you can trigger events on other elements using an event on a particular element!

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

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

you can use Jquery to bind an event to the click. and there do what you want:

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

this is for disableing the buttons:

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

Are you looking for this

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

});

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM